I want to get today’s date. Using Now(), I get both date and time but I need date only.
How to get it?
Thanks
Furqan
I want to get today’s date. Using Now(), I get both date and time
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Use
System.DateTime.Today. Some additional notes:While you’re only interested in the date, you still get a
System.DateTimeobject. That is, there still is a time portion in the returned value, but it’s left blank (all zeroes).It’s important to remember this when you compare dates. If you want to compare two dates, and you’ve fetched one date via
DateTime.Todayand another date viaDateTime.Now, then these two dates will not be equal — precisely because one has the time set and the other doesn’t.In VB.NET, the
Datekeyword is equivalent to theSystem.DateTimetype. So you can write:P.S.: It just occurred to me that it might be a good idea to write
Date.Today, butDateTime.Now, in order to make it even more explicit that the former property only returns the date portion, while the latter returns both a date and time portion.