• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 13238
  • Last Modified:

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
0
sbornstein2
Asked:
sbornstein2
1 Solution
 
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now