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

[b]Converting time function[/b]

Status
Not open for further replies.

strebor

Technical User
Nov 24, 2004
66
US
If one has a date-time value, such as 1152227980.843, how can that be converted to something like mmm-dd-year hh:ss ?

Does anyone know of a vbscript function that can do that?

strebor
 
Not unless you know the meaning of the number.
 
Absolute, relative (an oxymoron) to time immemorial? And in unknown unit?
 
It is a unix system time stamp. I believe it is the number of seconds since a date in the past. I'm trying to find out the date. I think that I can do something like:

baseDate = #1-Jan-1970#
dateToConvert = 1152227980.843

myDate = DateAdd ("s",dateToConvert,baseDate)

MsgBox myDate

This seems to work... assuming that the base date is correct.

strebor
 
that number is number of seconds since 1970 (which is referred to as absolute time in db2), but db2 calculates it from way back when. i.e. 1 a.d. it's used as a timestamp.

cheers.
 
{i]It is a unix system time stamp[/i]
I confirm that the epoch is 1970-01-01

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
It works. It is in GMT so I have to make an adjustment to my local time and account for daylight savings time. Thank you both for your commentary. For some reason I believed there was a vb function that would convert unix time stamps... but there may not be standard starting time to convert from. I guess there is the dateAdd function, which does the trick. Anyway, there is no time but the present. Thanks!

strebor
 
Ok... here is the result:
Code:
Set dictDLSD = CreateObject("Scripting.Dictionary")

dictDLSD("2001") = Array("04/01/2001 02:00:00", "10/28/2001 02:00:00")
dictDLSD("2002") = Array("04/07/2002 02:00:00", "10/27/2002 02:00:00") 
dictDLSD("2003") = Array("04/06/2003 02:00:00", "10/26/2003 02:00:00") 
dictDLSD("2004") = Array("04/04/2004 02:00:00", "10/31/2004 02:00:00")
dictDLSD("2005") = Array("04/03/2005 02:00:00", "10/30/2005 02:00:00")
dictDLSD("2006") = Array("04/02/2006 02:00:00", "10/29/2006 02:00:00")
dictDLSD("2007") = Array("03/11/2007 02:00:00", "11/04/2007 02:00:00")
dictDLSD("2008") = Array("03/09/2008 02:00:00", "11/02/2008 02:00:00")
dictDLSD("2009") = Array("03/08/2009 02:00:00", "11/01/2009 02:00:00")
dictDLSD("2010") = Array("03/14/2010 02:00:00", "11/07/2010 02:00:00")
dictDLSD("2011") = Array("03/13/2011 02:00:00", "11/06/2011 02:00:00")




baseDate = #1-Jan-1970#
dateToConvert = 1095463656.792

myDate = DateAdd ("s",dateToConvert - (8 * 60 * 60),baseDate) 

MsgBox DateAdd("h", ChkForDLST(myDate),myDate)


Function ChkForDLST(vTimeToCheck)
	
	vMyTest = Year(vTimeToCheck)
	
	If DateValue(vTimeToCheck) > DateValue(dictDLSD (CStr(vMyTest))(0)) And DateValue(vTimeToCheck) < DateValue(dictDLSD (CStr(vMyTest))(1)) Then
		ChkForDLST = 1
	Else
		ChkForDLST = 0
	End If

End Function

strebor
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top