Sign in to follow this  
Followers 0
arcker

VBconvert + date

9 posts in this topic

#1 ·  Posted (edited)

hi everyone,

i would like ti know is it's possible to add a value to a date, and return the new date

in vbs it's simple :

lngDate = #1/1/1601# + (((lngHigh * (2 ^ 32)) _
    + lngLow) / 600000000 - lngAdjust) / 1440
and lngdate is the new date

and i have another question

is auto-it supports unsigned numbers ?

thx

Edited by arcker

-- Arck System _ Soon -- Ideas make everything

"La critique est facile, l'art est difficile"

Projects :

[list] [*]Au3Service : Run your exe as service V3 / Updated 29/07/2013 Get it Here [/list]

Share this post


Link to post
Share on other sites



Try the Function "_DateAdd" found in the "include" folder.

From the help file:

#include <Date.au3>

; Add 5 days to today
$sNewDate = _DateAdd( 'd',5, _NowCalcDate())
MsgBox( 4096, "", "Today + 5 days:" & $sNewDate )

; Subtract 2 weeks from today
$sNewDate = _DateAdd( 'w',-2, _NowCalcDate())
MsgBox( 4096, "", "Today minus 2 weeks: " & $sNewDate )

; Add 15 minutes to current time
$sNewDate = _DateAdd( 'n',15, _NowCalc())
MsgBox( 4096, "", "Current time +15 minutes: " & $sNewDate )

; Calculated eventlogdate which returns second since 1970/01/01 00:00:00 
$sNewDate = _DateAdd( 's',1087497645, "1970/01/01 00:00:00")
MsgBox( 4096, "", "Date: " & $sNewDate )

AutoIt supports the variant datatype. Can contain numbers and strings,

but no "unsigned" data is supported.


It's my job to comfort the disturbed and to disturb the comfortable.

Share this post


Link to post
Share on other sites

yes, i've seen this feature, but doesn't support dates under year 1900...

my startpoint must be 01/01/1601 00:00:00

it's the zero point of active directory dates

i've tried to modify the dates.au3 but after it returns negatives values

argh


-- Arck System _ Soon -- Ideas make everything

"La critique est facile, l'art est difficile"

Projects :

[list] [*]Au3Service : Run your exe as service V3 / Updated 29/07/2013 Get it Here [/list]

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Hi,

Here's a function to emulate vbscript;

"_StampDateAdd($lngHigh,$lngLow,$lngAdjust)"

I assume you can find the high , low values mentioned; here is example using vbscript object!

I don't know if native AutoIt can do it! nor do I know about unsigned; ....

;vbs5.au3

; Here's a function to emulate vbscript;

; I assume you can find the high , low values mentioned; here is example using vbscript object!

; I don't know if native AutoIt can do it!

#include<Date.au3>

MsgBox(0,"Test de vérification","Date "& _

@CRLF&_StampDateAdd(29760000,100,0))

Func _StampDateAdd($lngHigh,$lngLow,$lngAdjust)

$code= "Function Integer8Date(lngHigh,lngLow,lngAdjust)"

$code=$code & @CRLF & "lngDate = #1/1/1601# + (((lngHigh * (2 ^ 32)) + lngLow) / 600000000 - lngAdjust) / 1440"

$code=$code & @CRLF & "Integer8Date = CDate(lngDate)"

;$code=$code & @CRLF & " Account for bug in IADsLargeInteger property methods."

;$code=$code & @CRLF & "If (lngHigh = 0) And (lngLow = 0) Then"

;$code=$code & @CRLF & "lngAdjust = 0"

;$code=$code & @CRLF & "End If"

$code=$code & @CRLF & "end Function"

$vbs = ObjCreate("ScriptControl")

$vbs.language="vbscript"

$vbs.addcode($code)

$retour = $vbs.run("Integer8Date",$lngHigh,$lngLow,$lngAdjust)

$vbs=""

$Year=StringLeft($retour,4)

$Month=StringMid($retour,5,2)

$Day=StringMid($retour,7,2)

$Hour=StringMid($retour,9,2)

$Minute=StringMid($retour,11,2)

$Second=StringMid($retour,13,2)

ConsoleWrite($retour)

$retourstring=$Year&"/"&$Month&"/"&$Day&" "&$Hour&":"&$Minute&":"&$Second

return $retourstring

EndFunc ;==>_StampDateAdd

Best, Randall Edited by randallc

Share this post


Link to post
Share on other sites

OK,

Here is a way to do the adjustment;

i can't do it in regread in AutoIt; I don't think it accepts those long integers/ varriant options, or else not accurately;

;vbstime6.au3 v _0_2

;vbs5.au3

; Here's a function to emulate vbscript;

; I assume you can find the high , low values mentioned; here is example using vbscript object!

; I don't know if native AutoIt can do it!

#include<Date.au3>

#include<Array.au3>

MsgBox(0,"Test de vérification","Date "& _

@CRLF&_StampDateAdd(29760000,100))

Func _StampDateAdd($lngHigh,$lngLow)

Local $s_Quotes='"'

;""

$code= "Function Integer8Date(lngHigh,lngLow)"

$code = $code & @CRLF & "Dim WshShell, lngBiasKey,lngTZBias"

$code = $code & @CRLF & 'Set WshShell = CreateObject("WScript.Shell")'

$code = $code & @CRLF & "lngBiasKey=WshShell.RegRead(""HKLM\System\CurrentControlSet\Control\TimeZoneInformation\ActiveTimeBias"")"

$code = $code & @CRLF & "If UCase(TypeName(lngBiasKey)) = ""LONG"" Then"

$code = $code & @CRLF & "lngTZBias = lngBiasKey"

$code = $code & @CRLF & "ElseIf UCase(TypeName(lngBiasKey)) = ""VARIANT()"" Then"

$code = $code & @CRLF & "lngTZBias = 0"

$code = $code & @CRLF & "For k = 0 To UBound(lngBiasKey)"

$code = $code & @CRLF & "lngTZBias = lngTZBias + (lngBiasKey(k) * 256^k)"

$code = $code & @CRLF & "Next"

$code = $code & @CRLF & "End If"

$code=$code & @CRLF & "lngDate = #1/1/1601# + (((lngHigh * (2 ^ 32)) + lngLow) / 600000000 - lngTZBias) / 1440"

$code=$code & @CRLF & "Integer8Date = CDate(lngDate)"

$code=$code & @CRLF & "end Function"

msgbox(0,"",$code)

ConsoleWrite($code)

$vbs = ObjCreate("ScriptControl")

$vbs.language="vbscript"

$vbs.addcode($code)

$retour = $vbs.run("Integer8Date",$lngHigh,$lngLow)

$vbs=""

$Year=StringLeft($retour,4)

$Month=StringMid($retour,5,2)

$Day=StringMid($retour,7,2)

$Hour=StringMid($retour,9,2)

$Minute=StringMid($retour,11,2)

$Second=StringMid($retour,13,2)

ConsoleWrite($retour)

$retourstring=$Year&"/"&$Month&"/"&$Day&" "&$Hour&":"&$Minute&":"&$Second

return $retourstring

EndFunc ;==>_StampDateAdd

Randall

Share this post


Link to post
Share on other sites

try to change the following in Date.au3:

Line 377: If $asDatePart[1] < 1600 Or $asDatePart[1] > 2999 Then Return (0)

And than this works fine for me:

#include<date.au3>
$Days = _DateDiff('d',"1601/01/01",_NowCalcDate())
ConsoleWrite('@@ Debug(2) : $Days since 01/01/1601= ' & $Days & @lf & '>Error code: ' & @error & @lf);### Debug Console
$Newdate= _DateAdd('d',$Days + 25,"1601/01/01")
ConsoleWrite('@@ Debug(4) : $Newdate = ' & $Newdate & @lf & '>Error code: ' & @error & @lf);### Debug Console

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

@JdeB

why is that line there anyways ?

The idea at the time was to force people to use the 4 digit year and assumption was that nobody would need a date before 1900 anyways...


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0