C#

Moderators: None (Apply to moderate this forum)
Number of threads: 2720
Number of posts: 5746

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
DateTime Problem Posted by alphapp on 1 Apr 2004 at 6:30 AM
This message was edited by alphapp at 2004-4-5 23:50:49

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


Report
Re: DateTime Problem Posted by mk_swati on 8 Jan 2005 at 6:10 AM
: This message was edited by alphapp at 2004-4-5 23:50:49

: 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
:
:
:

Report
Re: DateTime Problem Posted by bgrommes on 10 Jan 2005 at 11:14 PM
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)




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.