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?
 
TechTiger007Connect With a Mentor Commented:
try this
DateTime.Now.ToString("dd/MM/yyyy a't' hh:mm tt")
0
 
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
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.