By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,985 Members | 1,161 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,985 IT Pros & Developers. It's quick & easy.

Formatting a datetime var for simple display

P: n/a
I have a datetime object named day1 that I want to display as just
3/29/2006 :

Response.Write(day1);

...but this will display the long default 3/29/2005 12:00 AM .
Using Response.Write(day1.ToShortDate()); is illegal syntax, not sure
how to format this while using Response.Write

chum

Mar 29 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Look at DateTime.ToString(<format>).

"Chumley Walrus" wrote:
I have a datetime object named day1 that I want to display as just
3/29/2006 :

Response.Write(day1);

...but this will display the long default 3/29/2005 12:00 AM .
Using Response.Write(day1.ToShortDate()); is illegal syntax, not sure
how to format this while using Response.Write

chum

Mar 29 '06 #2

P: n/a
If day1 is a System.DateTime object the method ToShortDate() is not
defined. Try ToShortDateString() instead:

DateTime date = DateTime.Now;
Response.Write(date.ToShortDateString());

-Carl

Mar 29 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.