473,426 Members | 1,458 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,426 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 15362
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Simon Brooke | last post by:
I'm investigating a bug a customer has reported in our database abstraction layer, and it's making me very unhappy. Brief summary: I have a database abstraction layer which is intended to...
2
by: amith | last post by:
hi I have written javascript for comparing two dates in US format and finding out whether the start date is greater than the end date and vice versa. In this attempt i have instantiated the...
4
by: Richard Hollenbeck | last post by:
I'm trying to write some code that will convert any of the most popular standard date formats twice in to something like "dd Mmm yyyy" (i.e. 08 Jan 1908) and compare the first with the second and...
3
by: Lyn | last post by:
Hi, I am developing a project in which I am checking for records with overlapping start/end dates. Record dates must not overlap date of birth, date of death, be in the future, and must not...
5
by: Macca | last post by:
Hi, I have a table which has a date/time field. I am storing them as follows :- 01/01/2005 11:25 01/01/2005 19:44 02/01/2005 05:04
12
by: Assimalyst | last post by:
Hi, I have a working script that converts a dd/mm/yyyy text box date entry to yyyy/mm/dd and compares it to the current date, giving an error through an asp.net custom validator, it is as...
20
by: andreas | last post by:
When I copy a vb.net project using date formats from one PC with a windows date format f.e. dd/mm/yyyy to another PC having a format yy/mm/dd then I get errors. How can I change for a while in the...
30
by: fniles | last post by:
On my machine in the office I change the computer setting to English (UK) so the date format is dd/mm/yyyy instead of mm/dd/yyyy for US. This problem happens in either Access or SQL Server. In the...
4
by: OzNet | last post by:
I have some functions to calculate the working days in a given period. This includes a table that is queried to calculate the number of public holidays that don’t occur on a weekend. If I test...
11
ollyb303
by: ollyb303 | last post by:
Hello, I am using a dynamic crosstab report to track performance statistics for my company and I have hit a problem. I would like the option to track stats daily (for the last 7 complete...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.