DateTime Problem

[b][red]This message was edited by alphapp at 2004-4-5 23:50:49[/red][/b][hr]
hi all
i have a problem in System.DateTime class . i want to get current Date of system .
it return me date and time ( like : 3/3/2004 12:00:00 PM ) , i only want date section .
how can i do this . i dont want it in string , i want in date format .

OR
how can i change the time format to 24 hour format ( it must return : 3/3/2004 24:0:0)


thank u
ali farhad


Comments

  • : [b][red]This message was edited by alphapp at 2004-4-5 23:50:49[/red][/b][hr]
    : hi all
    : i have a problem in System.DateTime class . i want to get current Date of system .
    : it return me date and time ( like : 3/3/2004 12:00:00 PM ) , i only want date section .
    : how can i do this . i dont want it in string , i want in date format .
    :
    : OR
    : how can i change the time format to 24 hour format ( it must return : 3/3/2004 24:0:0)
    :
    : change format property of date to short
    : thank u
    : ali farhad
    :
    :
    :

  • DateTime is a type that inherently includes the time. There is no "date only" type in .NET.

    If you want to strip out the time component you can do so by subtracting a TimeSpan, along this line:

    TimeSpan timePortion = new TimeSpan(myDateTime.Hour,myDateTime.Minute,myDateTime.Second,myDateTime.Millisecond);
    DateTime dateWithoutTime = myDate - timePortion;

    However it still converts to a display string as midnight on that date. You can use format strings with ToString() to format it for 24 hours or whatever you want. Look up the following topics in VS help:

    Standard date and time format strings
    Custom date and time format strings

    --Bob

    : hi all
    : i have a problem in System.DateTime class . i want to get current Date of system .
    : it return me date and time ( like : 3/3/2004 12:00:00 PM ) , i only want date section .
    : how can i do this . i dont want it in string , i want in date format .
    :
    : OR
    : how can i change the time format to 24 hour format ( it must return : 3/3/2004 24:0:0)

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories