471,089 Members | 1,764 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,089 software developers and data experts.

Date Format

Hi,

I use DateTime.Now to display the current date and time. For instance,
it's default format is 2003-10-29 21:23:36.

How can I change the format as follows?

10/29/2003 9:23:36 PM

MM/DD/YY HH/MM/SS AM/PM

Thanks for help

Tom
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #1
5 15219
Tom,

When using the ToString method on the DateTime structure, you can use
the following format string to get the format that you wish:

M/D/yyyy h:m:s tt

If you want to have a leading zero for any of the arguments (month, day,
hour, minute, second), then double up the format character for that section.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- nick(dot)paldino=at=exisconsulting<dot>com

"Tom Pair" <ke*****@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Hi,

I use DateTime.Now to display the current date and time. For instance,
it's default format is 2003-10-29 21:23:36.

How can I change the format as follows?

10/29/2003 9:23:36 PM

MM/DD/YY HH/MM/SS AM/PM

Thanks for help

Tom
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 15 '05 #2
Tom
Hi,

I replaced DateTime.Now with DateTime.Now.ToString(). But,
the date is same as before.

Could you teach me how to get the M/D/yyyy h:m:s tt format
from that date string?

Thanks for help

Tom

-----Original Message-----
Tom,

When using the ToString method on the DateTime structure, you can usethe following format string to get the format that you wish:
M/D/yyyy h:m:s tt

If you want to have a leading zero for any of the arguments (month, day,hour, minute, second), then double up the format character for that section.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- nick(dot) paldino=at=exisconsulting<dot>com
"Tom Pair" <ke*****@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Hi,

I use DateTime.Now to display the current date and time. For instance, it's default format is 2003-10-29 21:23:36.

How can I change the format as follows?

10/29/2003 9:23:36 PM

MM/DD/YY HH/MM/SS AM/PM

Thanks for help

Tom
*** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!

.

Nov 15 '05 #3
Tom,

I don't understand what you are trying to do. The representation of a
DateTime structure in .NET is just that, an instance of the DateTime
structure.

If you want to get that date in a string that is formatted that way,
take the string that I posted, and then pass it into the ToString method,
like this:

// Get the current date/time in the string format we desire.
string pstrFormattedDateTime = DateTime.Now.ToString("M/D/yyyy h:m:s tt");
--
- Nicholas Paldino [.NET/C# MVP]
- nick(dot)paldino=at=exisconsulting<dot>com

"Tom" <ke*****@yahoo.com> wrote in message
news:06****************************@phx.gbl...
Hi,

I replaced DateTime.Now with DateTime.Now.ToString(). But,
the date is same as before.

Could you teach me how to get the M/D/yyyy h:m:s tt format
from that date string?

Thanks for help

Tom

-----Original Message-----
Tom,

When using the ToString method on the DateTime

structure, you can use
the following format string to get the format that you

wish:

M/D/yyyy h:m:s tt

If you want to have a leading zero for any of the

arguments (month, day,
hour, minute, second), then double up the format

character for that section.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- nick(dot)

paldino=at=exisconsulting<dot>com

"Tom Pair" <ke*****@yahoo.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
Hi,

I use DateTime.Now to display the current date and time. For instance, it's default format is 2003-10-29 21:23:36.

How can I change the format as follows?

10/29/2003 9:23:36 PM

MM/DD/YY HH/MM/SS AM/PM

Thanks for help

Tom
*** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it!

.

Nov 15 '05 #4
I tried to use DateTime.Now.ToString("M/D/yyyy h:m:s tt")

The time is correct. But, the date prints 10-D-2003.

If I use DateTime.Now.ToString("m/d/yyyy h:m:s tt")

The date prints 39-10-2003.

If I use DateTime.Now.ToString("M/d/yyyy h:m:s tt")

The date prints 10-10-2003.

How can the date print 10/10/2003? or, it is no way to do it?

Thanks for your help.



*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #5
> How can the date print 10/10/2003? or, it is no way to do it?

Use this:

dd/MM/yyyy

Use the "exact" spelling, including upper and lower case.

/m
Nov 15 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

15 posts views Thread by Simon Brooke | last post: by
4 posts views Thread by Richard Hollenbeck | last post: by
5 posts views Thread by Macca | last post: by
12 posts views Thread by Assimalyst | last post: by
20 posts views Thread by andreas | last post: by
30 posts views Thread by fniles | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.