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

UNIX timestamp conversion 1

Status
Not open for further replies.

Sharkfin01

Programmer
Sep 26, 2001
13
GB
Hello, is there a function that can convert a UNIX timestamp (seconds since Jan 1, 1970) to format:

mm/dd/yyyy hh:mm:ss?

The format is flexible, but I do need to get it down to minute resolution. Too bad vbscript doesn't have a handy date() function like PHP...grrr
 
vbscript does have a handy date function. check this out:

UNIXdate = DateAdd("s", UNIXdatestamp, "1/1/70")

Response.Write NewDate


In the DateAdd function, "s" is for seconds, UNIXdatestamp would be whatever variable holds your UNIX date stamp (which would be number of seconds to add to the last parameter), and "1/1/70" holds the starting date.

Thus, "1/1/70" + UNIXdatestamp (# of seconds) = Date
 
Thanks for the help:
Now of course, I have a followup. Is there anyway to take a formatted date: yyyy-mm-dd hh:mm:ss
into Excel's "timestamp"--which is the number of days since Jan 1, 1970.
 
UNIXdatestamp = DateDiff("s", "1/1/70", NOW)

Actually, I did this first, so that I would have the datestamp to work with in the DateAdd function!

:-Q

 
oops. in the above function, just replace NOW with your formatted date variable..... i used this to create today's UNIX date stamp......

:cool:
 
oops. :~/ in the above function, just replace NOW with your formatted date variable..... i used this to create today's UNIX date stamp......


 
sorry again. when i submitted the first one, it errored out so i didn't think it submitted. oh well.
 
ok, since I'm not at my work PC now, I'm going to ask a dunce question. If I were to enter 10/10/2001 12:00:00 into your "NOW", I would get the equivalent Excel "timestamp"?
 
enter it as a text string: "10/10/2001 12:00:00"

I did, and this is the result - is this what you would expect?

timestamp: 1002715200
 
Indeed it is..thanks very much for your help. This will most definitely come in handy tomorrow..
 
This is odd...I just telneted to my work PC and entered this:

a=datediff("s", "1/1/70", "10/10/2001 24:00:00")
and i get the following error:

Type mismatch: '[string: "10/11/2001 24:00:00"]'

where'd I goof?
 
Nevermind..I jsut threw the string into a variable and it works...losing my patience I guess :p
 
well, that's odd, cuz it worked like this for me:

a=datediff("s", "1/1/70", "10/10/2001 24:00:00")

but, whatever works, that's the key. X-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top