Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

vbscript date functions

Status
Not open for further replies.

ErrolDC

MIS
May 26, 2004
72
US
Hi. Is there a simple way to get the date in YYYYMMDD format in vbscript?

Thx again!

Errol
 
Year(Date) & Right("0" & Month(Date),2) & Right("0" & Day(Date),2)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Okay, i understand that. Why are you using the number 2?
 
PHV is forcing the month and day to be formatted as 2-digit (leading zero) values. Since most scripts rearely deal with years before the year 1000, doing to same thing to force a 4-digit year is usually unnecessary.
 
He is using the Right() function to take the 2 characters off the end.

So if his month is january the Month() function will return 1 .... so "0" & 1 = "01"

And his month is december the Month() function will return 12 ... so "0" & 12 = "012"

By taking the 2 rightmost character he will always have a two character string.... the leading zero gets chopped off for October, November, & December (010, 011, 012)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top