Jump to content
Xtreme .Net Talk

Potentially easily solvable question-Help needed! Date/Time Picker


Recommended Posts

Posted

Hello,

Im writing a project that requires the user to select a time using the date/time picker. After the user selects a time that he/she had last done something I want to get that time (DateTimePicker1.Value) and then figure out how many---(days, hours, minutes, seconds) it has been since the time they selected. So if they selected "Sunday, March 16th, 2003 11:19AM" It would say ..."1 day, 0 hours, 0 mins, 0 seconds" ..

It's been a while since Ive coded anything and I'm really trying to get the hang of it all again. Any help I might recieve is greatly appreciated. Thanks.

  • *Gurus*
Posted

You can do this by subtracting the date returned by the control from the date now:

 

Dim ts As TimeSpan = DateTime.op_Subtraction(DateTime.Now, DateTimePicker1.Value)

 

TimeSpan ts = DateTime.Now - DateTimePicker1.Value;

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Posted

Excellent--I did this...

 

 Dim ts As TimeSpan = DateTime.op_Subtraction(DateTime.Now, DateTimePicker1.Value)
       Forms.frm1.Label12.Text = System.Convert.ToString(ts) 

Works great Thank you

Posted
One last question---The Time returned is always the time of day equal to vurrent system time--How does the user select a time of day as well as a day on the date/time picker? Can both date and time be selected with one date/time picker? I figured out you could select format to time but that seems to take away the 'date' part of it. Any ideas? Thanks again. =)
  • 4 months later...
Posted

Public Sub SetMyCustomFormat()
   ' Set the Format type and the CustomFormat string.
   dateTimePicker1.Format = DateTimePickerFormat.Custom
   dateTimePicker1.CustomFormat = "yyyy-M-d:H:m"
End Sub 'SetMyCustomFormat

 

 

Note The Format property must be set to DateTimePickerFormat.Custom for this property to affect the formatting of the displayed date/time.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...