How to get date part from datetime?

11,484

Solution 1

Use the Date property of the datetime field (if you need to do this on the client)

Solution 2

DateTime.Date will give you just the date portion of the datetime if you want to pass it around your application

Solution 3

If you are inside of .NET as it appears that you are based on the tags

dim myDate as DateTime = DateTime.Parse('4/1/2009 8:00:00AM')
dim myDesiredValue as String = myDate.ToShortDateString()

Solution 4

This is C# (yeah - I know you want VB) but given that none of the following uses anything other than DataTime then it should give you want you want...

        string foo = "4/1/2009 8:00:00AM";
        DateTime bar = DateTime.Parse(foo);
        string output = bar.ToString("M/d/yyyy");
Share:
11,484
num3ri
Author by

num3ri

Updated on July 26, 2022

Comments

  • num3ri
    num3ri almost 2 years

    Duplicate: How to truncate a date in .net?

    I have datetime field containing '4/1/2009 8:00:00AM'. I want to get '4/1/2009' without the time.