I was wondering if someone could help me.
I'm very new at ASP I want to format the current date and time as follows:
yyyy-mm-dd hh:mm:ss
But all i can do is the following
Response.Write Date
Can someone help me out please.
I was wondering if someone could help me.
I'm very new at ASP I want to format the current date and time as follows:
yyyy-mm-dd hh:mm:ss
But all i can do is the following
Response.Write Date
Can someone help me out please.
Date formatting options are limited in Classic ASP by default, there is a function
FormatDateTime()
which can format your date is various ways based on the servers regional settings.For more control over date formatting though there are built in date time functions
Year(date)
- Returns a whole number representing the year. PassingDate()
will give back the current year.Month(date)
- Returns a whole number between 1 and 12, inclusive, representing the month of the year. PassingDate()
will return the current month of the year.MonthName(month[, abbv])
- Returns a string indicating the specified month. Passing inMonth(Date())
as the month will give back the current Month string. As suggested by @MarthaDay(date)
- Returns a whole number between 1 and 31, inclusive, representing the day of the month. PassingDate()
will return the current day of the month.Hour(time)
- Returns a whole number between 0 and 23, inclusive, representing the hour of the day. PassingTime()
will return the current hour.Minute(time)
- Returns a whole number between 0 and 59, inclusive, representing the minute of the hour. PassingTime()
will return the current minute.Second(time)
- Returns a whole number between 0 and 59, inclusive, representing the second of the minute. PassingTime()
will return the current second.The functions
Month()
,Day()
,Hour()
,Minute()
andSecond()
all return whole numbers. Luckily there is an easy workaround that lets you pad these values quicklyRight("00" & value, 2)
what it does is append00
to the front of the value then from the right take the first two characters. This ensures that all single digit values return prefixed with a0
.Note: You can build the date string in one call but decided to break it down into the three variables to make it easier to read.
Date
variable).