Simple Question on datetimepicker in VB
Simple Question on datetimepicker in VB
Simple Question on datetimepicker in VB
Simple Question on datetimepicker in VB
Simple Question on datetimepicker in VB
Simple Question on datetimepicker in VB Simple Question on datetimepicker in VB Simple Question on datetimepicker in VB Simple Question on datetimepicker in VB Simple Question on datetimepicker in VB Simple Question on datetimepicker in VB Simple Question on datetimepicker in VB Simple Question on datetimepicker in VB
Simple Question on datetimepicker in VB Simple Question on datetimepicker in VB
Simple Question on datetimepicker in VB
Go Back  Xtreme Visual Basic Talk > > > Simple Question on datetimepicker in VB


Reply
 
Thread Tools Display Modes
  #1  
Old 06-12-2011, 02:38 AM
vbnewbiee vbnewbiee is offline
Newcomer
 
Join Date: Jun 2011
Posts: 1
Question Simple Question on datetimepicker in VB


Hi folks,

I am a new joiner on this forum and have a very simple question - hoping someone can help me.

I want to save datetimepicker value of date and time in two separate text files. Currently, when I select a date from datetimepicker and save it in a text file it saves both date and time as below:

5/11/2011 8:25:06 PM

What I would like to happen is as below:

Datefile.txt saves 5/11/2011
Timefile.txt saves 8:25:06 PM

Alternative solution that can work for me would be, if the time (only the TIME) can be modified after saving as below:

saved datetime into text file is 5/11/2011 8:25:06 PM

How can I modify the time only to say 12:00:00 PM.

By doing so I would like to keep time as 12:00:00 but date can be changed by the user using the datetime picker.

Any ideas? Thanks in advance friends..
Reply With Quote
  #2  
Old 06-12-2011, 09:11 AM
AtmaWeapon's Avatar
AtmaWeaponSimple Question on datetimepicker in VB AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

If you want to save the date and time values separately, use the Date and TimeOfDay properties of the DateTime object. TimeOfDay returns a TimeSpan, so be prepared to use that type. Keep in mind separating your dates and times like this will make it much more difficult to read them back from the files (if that is your aim.)

The Date property returns a DateTime with the appropriate date and the time set to its default value of 12 AM. If you want a different "default" value, you have to make it so. One way would be to use DateTime.AddHours() and other methods to manipulate it the way you want. I generally use the constructor to create a new one. Here's an example that returns a DateTime with the same date but a time of 12 PM:
Code:
Function GetDateWithDefaultTime(ByVal input As DateTime)
    Return New DateTime(input.Year, _
                        input.Month, _
                        input.Day, _
                        12, _
                        0, _
                        0)
End Function
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Simple Question on datetimepicker in VB
Simple Question on datetimepicker in VB
Simple Question on datetimepicker in VB Simple Question on datetimepicker in VB
Simple Question on datetimepicker in VB
Simple Question on datetimepicker in VB
Simple Question on datetimepicker in VB Simple Question on datetimepicker in VB Simple Question on datetimepicker in VB Simple Question on datetimepicker in VB Simple Question on datetimepicker in VB Simple Question on datetimepicker in VB Simple Question on datetimepicker in VB
Simple Question on datetimepicker in VB
Simple Question on datetimepicker in VB
 
Simple Question on datetimepicker in VB
Simple Question on datetimepicker in VB
 
-->