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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Manipulating the system time

Status
Not open for further replies.

chouck

MIS
Jan 30, 2005
32
US
Hello All,

I have what I think is an easy question, I just haven't been able to figure it out. I'm trying to get the pc to echo the date format a certain way and haven't been able to figure it out

when I run this code :

currdate = year(date) & "/" & month(date) & "/" & day(date)
wscript.echo currdate

this is returned: 2005/8/11

but I need it to return 2005/08/11. Does anyone have any ideas ? Thanks in advance
 
currdate = 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 FAQ181-2886
 
PHV,

Thank you so much. That worked like a champ!!! perfect :)

I don't suppose you could kind of explain what you did there, i kind of get the left right set thing but not really ? And would like to understand. Thanks again!
 
Right("0" & Month(Date),2)
Right("0" & Month(Date),2)
Add a 0 to the left of the actual month number
Right("0" & Month(Date),2)
and get the 2 rightmost characters.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
I use this code to cope with single/double digit months/days:

Code:
	if len(Month(Now)) < 2 then 
	strMonth = "0" & Month(Now)
	else 
	strMonth = Month(Now)
	end if

	if len(Day(Now)) < 2 then 
	strDay = "0" & Day(Now)
	else 
	strDay = Day(Now)
	end if

	strDate = Year(Now) & "-" & strMonth & "-" & strDay
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top