Questions DateTime.Now

  • Thread starter Thread starter David
  • Start date Start date
D

David

Hello.

How can I get only date or only time from DateTime.Now?
For example I want to assign current date and current time to some labels.

Thank you.
 
Use DateTime.Now, but display the string as you need it (i.e. time only,
short data, long date, etc.)
 
Hello.

How can I get only date or only time from DateTime.Now?
For example I want to assign current date and current time to some labels.

Thank you.

Format appropriately, or use one of the built in methods such as
DateTime.Now.ToShortDateString() and DateTime.Now.ToShortTimeString().
 
David,
In addition to the other comments about formatting, which is probably what
you want as you to "assign to some labels".

In calculations: You can use DateTime.Date to get just the Date part of a
DateTime. You can use DateTime.TimeOfDay to get just the Time part of a
DateTime.

Hope this helps
Jay
 
Back
Top