Page 1 of 1
Add date?
Posted: Sun Mar 01, 2009 4:09 pm
by SFSxOI
I have this year and time: 1601/01/01 00:00:00 (format is yyyy/mm/dd hh:mm:ss
I want to add an interval of seconds to that year and time. I can't get the AddDate function to work for me properly. I know AutoIt has a _DateAdd function that does it using this
Code: Select all
_DateAdd("S", iSeconds, "1601/01/01 00:00:00")
where:
"S" = the type to add - in this case seconds
iSeconds = the interval to add
"1601/01/01 00:00:00" = the date and time for the interval to be added to
How can I do this in PureBasic ? (No, the PB AddDate doesn't seem to be able to do it, unless i'm doing i wrong)
Posted: Sun Mar 01, 2009 5:12 pm
by Little John
You can use
these date functions. Please see also the first question and my answer to it.
Regards, Little John
Posted: Sun Mar 01, 2009 5:26 pm
by SFSxOI
Little John wrote:You can use
these date functions. Please see also the first question and my answer to it.
Regards, Little John
Yep, saw those Little John, looks nice and interesting too. You surely must have gotten many headaches while figuring it out.

But unfortunatley it doesn't work for me. Is this right?
Code: Select all
dtm.DateTime
dtm\year = 1601
dtm\month = 1
dtm\day = 1
dtm\hour = 0
dtm\min = 0
dtm\sec = 0
Debug DateQ(dtm)
Posted: Sun Mar 01, 2009 6:04 pm
by Little John
SFSxOI wrote:Yep, saw those Little John, looks nice and interesting too. You surely must have gotten many headaches while figuring it out.

I always enjoy this good feeling, when the headaches are disappearing.
SFSxOI wrote:But unfortunatley it doesn't work for me. Is this right?
Code: Select all
dtm.DateTime
dtm\year = 1601
dtm\month = 1
dtm\day = 1
dtm\hour = 0
dtm\min = 0
dtm\sec = 0
Debug DateQ(dtm)
The code as is works in the range from year 1970 to year 32548. So it will not work for the year 1601. For your purpose, a tiny modification of my code is required. That's why I wrote
Please see also the first question and my answer to it.
Regards, Little John
Posted: Sun Mar 01, 2009 7:56 pm
by SFSxOI
yep, did all that, still can't use it either propery to duplicate the autoit function or i'm not using it properly. Oh well, back to the drawing board. Thanks

Posted: Sun Mar 01, 2009 8:40 pm
by Little John
What
exactly is the problem? I'm pretty sure we can solve it.
I did this now:
1) At the very beginning of my mentioned date code, I replaced
with
and I saved the file as "DateQ.pbi".
2) Running the following code
Code: Select all
XIncludeFile "DateQ.pbi"
Define dtm.DateTime, seconds.q
With dtm
\year = 1601
\month = 1
\day = 1
\hour = 0
\min = 0
\sec = 0
EndWith
seconds = DateQ(dtm)
seconds + 3*86400 ; add the seconds that make up 3 days
SplitDateQ(seconds, dtm)
With dtm
Debug \year
Debug \month
Debug \day
Debug \hour
Debug \min
Debug \sec
EndWith
outputs
1601
1
4
0
0
0
Isn't that what you are after?
Regards, Little John
Posted: Sun Mar 01, 2009 9:14 pm
by SFSxOI
Actually i'm converting some of this autoit code and I needed a way to convert the filetime to a CIM Date time in Vista for one particular thing , the InstalledOn date in the Win32_QuickFixEngineering in WMI because in Vista it changed. Where as it returns a convertable and readable date in XP, in Vista it returns something like this instead > 01c86ac114b1e194. So, I had this autoit code and tried it out and it converts the screwed up Vista InstalledOn date to a readable and convertable CIM datetime thats eaisly converted to a human readable date time. So I know the autoit routine works already, and its the only one i've found except for some .Net C++ stuff that the rest of the world is using. Here is what the autoit code looks like, i'm just hung up on the date conversion for that one property.
Code: Select all
$high = Dec(StringMid($sInstalledOn, 1, 8))
$low = Dec(StringMid($sInstalledOn, 9))
$int64 = $high * 2^32 + $low
$iSeconds = Floor($int64 / 10000000)
$sInstalledOn = _DateAdd("S", $iSeconds, "1601/01/01 00:00:00")
and here is what i'm working with to convert it:
Code: Select all
Procedure.s getinstalledon(InstalledOn_in.s)
high.q = Val("$" + Mid(InstalledOn_in, 1, 8))
low.q = Val("$" + Mid(InstalledOn_in, 9, 8))
int64.q = high * Pow(2, 32) + low
iSeconds.q = Round(int64 / 10000000, #PB_Round_Nearest)
sInstalledOn = _DateAdd("S", iSeconds, "1601/01/01 00:00:00") ;<<<< this is still the autoit function I need to replace
EndProcedure
And...if your stuff works then i'll be able to replace the autoit date conversion routine thats still left in the above. So thats what i'm doing. I'm trying to get your code to work out for me but so far the expected values aren't returned
Posted: Sun Mar 01, 2009 10:00 pm
by Little John
What exactly is
$sInstalledOn?
Is it a string in the format "1601/01/01 00:00:00"?
Please note that #PB_Round_Nearest does not implement the floor() function. Use this instead:
Code: Select all
Macro Floor (_x_)
Round(_x_, #PB_Round_Down)
EndMacro
Regards, Little John
Posted: Sun Mar 01, 2009 10:24 pm
by SFSxOI
Little John wrote:What exactly is
$sInstalledOn?
Is it a string in the format "1601/01/01 00:00:00"?
Please note that #PB_Round_Nearest does not implement the floor() function. Use this instead:
Code: Select all
Macro Floor (_x_)
Round(_x_, #PB_Round_Down)
EndMacro
Regards, Little John
Yeah, thats why I did this above > iSeconds.q = Round(int64 / 10000000, #PB_Round_Nearest) (i'm experimenting with the round nearest and round down, I think in autoit it actually will round to the nearest)
no, its not in a string like that, the string looks like this > 01c86ac114b1e194 - notice the conversions from hex to quads above for seperating the 64 bit string into two parts.
also, the sInstalledOn is a WMI property of the Win32_QuickFixEngineering class in WMI. In Vista it produces a long 64 bit hex number like this > 01c86ac114b1e194 (it does not produce the value like this in winXP) So I need to convert that into a filetime which I can then convert into a CIM datetime and then a readable date and time. However, there is only one other way to do this aside from the autoit code above and that one other way is with .Net which you can't do in PureBasic. Thus the autoit code. This routine actually came from an autoit version of the Win32_QuickFixEngineering class, and i've tried this routine out in autoit and it works, so I know it works, so i want to convert it for use with PureBasic to add to everything else I did here >
http://www.purebasic.fr/english/viewtopic.php?t=36492
Posted: Sun Mar 01, 2009 10:37 pm
by SFSxOI
well, never mind...I guess... actually I just got it working! Turns out I didn't need to add the seconds to the date after all, all i needed to do was int64 + iSeconds and the WMI in Vista takes care of the rest. I found a very obscure reference on the 'net that indicated something other then what i was led to believe, tried it out, and the converted autoit code works in PB without the date add after all but doesn't work without it in autoit, go figure.
Thanks for your help though, I will keep your work with dates in mind as its very good.
heres my first working version for the odd InstalledOn conversion for Vista (needs srod's COMate), turned out to be eaisier then i thought:
Code: Select all
; needs uses srod's COMate
Procedure.s ConvertFILETIMEtoDateTime(filetime_in.s, UTC_True_False.i)
;converts a date in the string FILETIME format to the CIM datetime format
Define.COMateObject dateTime
dateTime = COMate_CreateObject("WbemScripting.SWbemDateTime")
If dateTime
datetime\Invoke("SetFileTime('" + filetime_in + "')")
If UTC_True_False = 0
cim_date_time_out$ = dateTime\GetStringProperty("GetVarDate(#False)") ; we get the local without UTC offset
EndIf
If UTC_True_False = 1
cim_date_time_out$ = dateTime\GetStringProperty("GetVarDate(#True)") ; we get the local with UTC offset
EndIf
EndIf
dateTime\Release()
ProcedureReturn cim_date_time_out$
EndProcedure
Procedure.s GetVistaInstalledOn(InstalledOn_in.s) ; input InstalledOn from Win32_QuickFixEngineering in Vista only
;test value for InstalledOn_in.s = 01c8ec35ed9110f1
high.q = Val("$" + Mid(InstalledOn_in, 1, 8))
low.q = Val("$" + Mid(InstalledOn_in, 9, 8))
int64.q = high * Pow(2, 32) + low
iSeconds.q = Round(int64 / 10000000, #PB_Round_Nearest)
date_out.q = int64 + iSeconds
out_date$ = Str(date_out); for test value above the file time here is 128612318604418288 which is exactly correct for the date shown below at the return
Installed_On_Vista_OFE$ = ConvertFILETIMEtoDateTime(out_date$, 0)
; get the date without UTC offset factored in
ProcedureReturn Installed_On_Vista_OFE$ ; returns the date in the format> i.e... 7/23/2008 1:24:20 AM
EndProcedure
Debug GetVistaInstalledOn("01c8ec35ed9110f1") ;< Vista test value for this computer
seems to be working correctly on Vista here and producing the correct information. Its not for XP, its a Vista only thing.