Monday, December 17, 2007

How to format the date to prefix the month or day with a zero

How to format the date to prefix the month or day with a zero

S T E P - 1

- We use some techniques to do it.

- First, add a zero in each number. For example:

"0" & Month(Now())

The output will be:

Jan 01

Feb 02

Mac 03

Apr 04

May 05

Jun 06

Jul 07

Aug 08

Sep 09

Oct 010

Nov 011

Dec 012

S T E P - 2

- We just got the last 2 digits from the output:

Right("0" & Month(Now()),2)

so the output will be:

Jan 01

Feb 02

Mac 03

Apr 04

May 05

Jun 06

Jul 07

Aug 08

Sep 09

Oct 10

Nov 11

Dec 12

<%

d = Right("0" & Month(Now()), 2) & "/" & _

Right("0" & Day(Now()), 2) & "/" & _

Year(Now()) & " " & _

Right("0" & Hour(Now()), 2) & ":" & _

Right("0" & Minute(Now()), 2) & ":" & _

Right("0" & Second(Now()), 2)

Response.Write d

%>


No comments: