ASP.Net/VB.Net - Current Date Time Format

How can I get the following for the current date and time:

 1/7/2008 at 8:36 PM
sbornstein2Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Göran AnderssonCommented:
You want the current date and time formatted in that specific way?

If you mean a format with day/month:

string formattedDate = DateTime.Now.ToString("d'/'M'/'yyyy a't' h':'mm tt");

If you mean a format with month/day:

string formattedDate = DateTime.Now.ToString("M'/'d'/'yyyy a't' h':'mm tt");

Explanation of the parts of the custom format strings:

d = day of month without leading zero
M = month without leading zero
yyyy = year as four digits
h = hours in 12 hour format without leading zero
mm = minutes with leading zero
tt = two character am/pm designaror

't' = the t character (to avoid that it is interpreted as a one character am/pm designator)
'/' = the / character (only / represents the date separator so it's culture dependant.)
':' = the : character (only : representes the time separator so it's cutlure dependant.)
0
GawaiCommented:
try
Dim d As New Date
d = d.Now
''Response.Write(d.ToShortDateString)
Response.Write("<BR>" & Format(d, "dd/MMM/yyyy"))

''Response.write(d)
0
TechTiger007Commented:
try this
DateTime.Now.ToString("dd/MM/yyyy a't' hh:mm tt")
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
OWASP: Threats Fundamentals

Learn the top ten threats that are present in modern web-application development and how to protect your business from them.

sbornstein2Author Commented:
perfect
0
Göran AnderssonCommented:
So you didn't want the date formatted the way that you said?

The suggestion that you accepted will format the date as 01/07/2008 at 08:36 PM, not 1/7/2008 at 8:36 PM.
0
bgb76Commented:
string formattedDate = DateTime.Now.ToString("d'/'M'/'yyyy a't' h':'mm tt");

If you mean a format with month/day:

string formattedDate = DateTime.Now.ToString("M'/'d'/'yyyy a't' h':'mm tt");

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.