|
-
Aug 7th, 2000, 08:08 AM
#1
Thread Starter
New Member
I want to make a function that will convert from a DATE/TIME datatype to a LONG datatype containing the number of seconds from 1-January-1970 to the supplied date.
The trick is that the seconds must always reflect seconds in GMT and the Date supplied may be from a different part of the year (Daylight Savings Time vs Standard Time). So, before converting to seconds, I must convert the DATE/TIME to GMT time.
How can I get the RULES for converting from a TIME in a particular timezone to GMT time? Ideally, it would be nice if I could also send as a parameter the Timezone.
-
Aug 7th, 2000, 02:15 PM
#2
Thread Starter
New Member
HHHEEELLLPPP!!!!! Anyone????
-
Aug 7th, 2000, 04:48 PM
#3
transcendental analytic
Shoudn't be that hard to convert to and from GMT:
Code:
GMTDate=DateAdd("h", -Zone, Date)
Date=DateAdd("h", Zone, GMTDate)
Also what do you mean by converting to long?`That you want to compress the data for file storage?
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Aug 7th, 2000, 05:17 PM
#4
Frenzied Member
Dates are stored (internally) as real numbers. The integer portion is the number of days from some point in time and I believe the decimal portion is the number of ticks since midnight (although it's been a long time since I've played with this). It is possible to convert a date using CDBL to this numeric format, you could then use the MOD function to remove the day portion...
-
Aug 7th, 2000, 05:32 PM
#5
Do you mean you want it in Long Date? To come out like: 1-January-1970?
Using Kedaman's code:
Code:
GMTDate = DateAdd("h", -Zone, Date)
Date = DateAdd("h", Zone, GMTDate)
NewGMTD = Format$(GMTDate, "m-dddd-yyyy")
NewDate = Format$(Date, "m-dddd-yyyy")
MsgBox "GMT Date: " & NewGMTD & Chr$(10) & "Date: " & NewDate
And to recieve the time:
Code:
GMTTime = DateAdd("h", -Zone, Time)
Time = DateAdd("h", Zone, GMTTime)
NewGMTT= Format$(GMTTime, "hh:mm:ss AMPM")
NewTime = Format$(Time, "hh:mm:ss AMPM")
MsgBox "GMT Time: " & NewGMTT & Chr$(10) & "Time: " & NewTime
Thanks for the code Kedaman..it will come in handy one day.
-
Aug 7th, 2000, 05:39 PM
#6
Thread Starter
New Member
The conversion to a Long datatype is not the problem... got that code down pat...
number of seconds since 1/1/1970 is:
CLng(ProvidedDate - CDate(DateSerial(1970, 1, 1)))
For the date part. The Time part is:
Hour(ProvidedDate) * 3600 + _
Minute(ProvidedDate) * 60 + _
Second(ProvidedDate)
My Problem is with the conversion to Greenwich Mean Time.
For example:
If it is the middle of Summer (Daylight Savings Time) and I ask to convert a date from the winter to a time stamp that is based on the number of seconds since GMT 1/1/1970 12:00 AM, I have to first convert the Date/Time to GMT.
In order to do this I have to know:
a) how many hours difference it is from GMT to the time zone of the computer running the program (not always the same)
b) if the date falls in DST or Standard Time. If it is in DST, then I also need to know what the difference is for DST as in some places it is not 1 hour.
-
Aug 7th, 2000, 05:42 PM
#7
Thread Starter
New Member
Just to clarify, by Long I mean a Long Integer holding the number of seconds from January 1st, 1970.
Thanks for the help...
Andrew
-
Aug 7th, 2000, 05:47 PM
#8
transcendental analytic
Something like this you want, andrew?
Code:
Function Date2Long(dte As Date) As Long
Date2Long = Second(dte) + Minute(dte) * 60 + Hour(dte) * 3600 + Day(dte) * 86400 + Month(dte) * 2764800 + (Year(dte) - 1998) * 35942400
End Function
Function Long2Date(lng As Long) As Date
Long2Date = CDate(Int(lng / 86400) Mod 32 & "." & Int(lng / 2764800) Mod 13 & "." & Int(lng / 35942400) + 1998 & " " & Int(lng / 3600) Mod 24 & ":" & Int(lng / 60) Mod 60 & ":" & lng Mod 60)
End Function
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Aug 7th, 2000, 05:55 PM
#9
transcendental analytic
nah, i think this is what you need (sorry i didn't refresh the browser for your last comments)
Code:
DateDiff("s", DateAdd("h", -Zone, CDate(DateSerial(1970, 1, 1))), Now)
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Aug 7th, 2000, 06:05 PM
#10
Thread Starter
New Member
Thanks kedaman, but how to I figure out what Zone should be?
Andrew
-
Aug 7th, 2000, 06:15 PM
#11
transcendental analytic
Do you mean if it's entered in your computer somewhere? in registry?
No idea
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Aug 7th, 2000, 06:18 PM
#12
transcendental analytic
ACtually, after searching around in registry i found this:
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\TimeZoneInformation\DaylightFlag
that's 02 00 00 00 (my timezone is GMT +2)
You could use my Registry module on my homepage for retrieving the value of it with Regval property
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Aug 7th, 2000, 06:19 PM
#13
Thread Starter
New Member
Yeah, I want to check the system (For example the regional settings) to find out what timezone the program is running in and then based on what it tells me adjust the date.
-
Aug 7th, 2000, 06:33 PM
#14
transcendental analytic
Would look like this:
Code:
YourLong=DateDiff("s", DateAdd("h", -asc(regval("HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\TimeZoneInformation\DaylightFlag")), CDate(DateSerial(1970, 1, 1))), Now)
remeber to add my registry module
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Aug 7th, 2000, 07:02 PM
#15
You can get your time zone (GMT) here: TimeZoneConverter.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|