How to get the current date without the time?
I am able to get date and time using:
DateTime now = DateTime.Now;
How can I get the current date and time separately in the DateTime format itself?
I am not using the DateTime picker dialog box in ASP.NET (C#).
Well, you can get just today's date as a
DateTime using the
DateTime today = DateTime.Today;
or more generally, you can use the
Date property. For example, if you wanted the UTC date you could use:
DateTime dateTime = DateTime.UtcNow.Date;
It's not very clear whether that's what you need or not though... if you're just looking to print the date, you can use:
or use an explicit format:
If you want a more expressive date/time API which allows you to talk about dates separately from times, you might want to look at the Noda Time project which I started. It's not ready for production just yet, but we'd love to hear what you'd like to do with it...
Read more... Read less...
See, here you can get only date by passing a format string. You can get a different date format as per your requirement as given below for current date:
Result : "9/1/2015"
Result : "9-1-2015"
Result : "2015-09-01"
Result : "2015-09-01 09:20:10"
For more details take a look at MSDN reference for Custom Date and Time Format Strings
Current Time :
Current Date :