Sign in to follow this  
Followers 0
SumTingWong

Additional date functions

7 posts in this topic

#1 ·  Posted (edited)

After noticing a lack of date functions in AutoIT, I have developed the attached dll with the following date functions:

Util_DateFormat

Util_TimeFormat

Util_DateDiff

Util_DateAdd

Util_DateFormat and Util_TimeFormat are basically wrappers for GetDateFormat and GetTimeFormat. You can find more info on these APIs on MSDN.

Util_DateDiff and Util_DateAdd are similar to the equivalent vb script:

Dim $naDllRet

$naDllRet = DllCall(@ScriptDir & "\AU3Date.dll", "int", "Util_DateFormat", _
                    "str", "dddd',' MMMM yyyy", _
                    "str", "", _
                    "int", @YEAR, _
                    "int", @MON, _
                    "int", @MDAY)
If @error = 0 Then
   MsgBox(4096,'debug:' , '$naDllRet:' & $naDllRet[2]);### Debug MSGBOX 
EndIf

$naDllRet = DllCall(@ScriptDir & "\AU3Date.dll", "int", "Util_TimeFormat", _
                    "str", "hh:mm:ss tt", _
                    "str", "", _
                    "int", @HOUR, _
                    "int", @MIN, _
                    "int", @SEC)
If @error = 0 Then
   MsgBox(4096,'debug:' , '$naDllRet:' & $naDllRet[2]);### Debug MSGBOX 
EndIf

$naDllRet = DllCall(@ScriptDir & "\AU3Date.dll", "int", "Util_DateDiff", _
                    "str", "y", _
                    "int", @YEAR, _
                    "int", @MON, _
                    "int", @MDAY, _
                    "int", @HOUR, _
                    "int", @MIN, _
                    "int", @SEC, _
                    "int", 1971, _
                    "int", 4, _
                    "int", 22, _
                    "int", 0, _
                    "int", 0, _
                    "int", 0)
If @error = 0 Then
   MsgBox(4096,'debug:' , '$naDllRet:' & $naDllRet[0]);### Debug MSGBOX 
EndIf

$naDllRet = DllCall(@ScriptDir & "\AU3Date.dll", "int", "Util_DateAdd", _
                    "int_ptr", @YEAR, _
                    "int_ptr", @MON, _
                    "int_ptr", @MDAY, _
                    "int_ptr", @HOUR, _
                    "int_ptr", @MIN, _
                    "int_ptr", @SEC, _
                    "str", "y", _
                    "int", -33)
If @error = 0 Then
   MsgBox(4096,'debug:' , '$naDllRet:' & _
          StringFormat("%02d/%02d/%04d %02d:%02d:%02d", _
          $naDllRet[3], _
          $naDllRet[2], _
          $naDllRet[1], _
          $naDllRet[4], _
          $naDllRet[5], _
          $naDllRet[6]));### Debug MSGBOX 
EndIf

Valid interval characters for Util_DateDiff and Util_DateAdd are:

y = year, M = month, d = month day, h = hour, m = minute, s = second

MSDN link to GetDateFormat for more info on valid date pictures for use with Util_DateFormat and Util_TimeFormat.

Test out it and let me know what you think.

If people find them useful, I will submit them to Jon.

AU3Date.dll

Edited by pacman

Share this post


Link to post
Share on other sites



Search for "DateNew.au3"

Share this post


Link to post
Share on other sites

Search for "DateNew.au3"

<{POST_SNAPBACK}>

I expect the DLL to work better and faster.

Am I wrong?

Share this post


Link to post
Share on other sites

Better? Doubtful. A good implementation in any language will always be equal. It could be slightly faster. However, I expect that offset some by loading the DLL. Plus, it requires a DLL, and I don't really see date functions going in as built-in functions given that JdeB has such a good library written in AutoIt.

Share this post


Link to post
Share on other sites

@JdeB - yours is a very good and complete implementation. Should definitely be a standard AU3 include.

I knocked my dll up this morning because I needed the date functions and didn't know about DateNew.au3.

Share this post


Link to post
Share on other sites

@JdeB - yours is a very good and complete implementation. Should definitely be a standard AU3 include.

<{POST_SNAPBACK}>

The DateNew.au3 is planned to replace the current Date.au3 include.

I knocked my dll up this morning because I needed the date functions and didn't know about DateNew.au3.

<{POST_SNAPBACK}>

No problem, i know that Nutster has Date functions on his ToDo list so they might make it in AutoIt3 at some point in time. Till then, i prefer using an Include over a DLL because it saves me from having to Fileinstall the DLL when the script is compiled and distributed. :idiot:

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