Jump to content

_DateCalc (new UDF)


seanhart
 Share

Recommended Posts

Looking through the functions included in the <date.au3> the one thing that's missing is a function that takes a system date and returns a standard "calc" date. (like the reverse of _DateTimeFormat). Searching the forums didn't reveal anything either, so attached is my UDF to solve this.

Syntax is:

_DateCalc ("date" [, "date format" [, "time format"]])

Parameters

date - Date in either system format or format provided (time is optional)

date format - [optional] format of date, default is system format

time format - [optional] format of time, default is system format

Return Value

Success: Date in format YYYY/MM/DD [HH:mm:ss]

Failure: Returns "", @ERROR = 1 (bad date), @ERROR = 2 (bad time)

Remarks

If 2 digit year is given, 81 - 99 becomes 1981 - 1999, otherwise 2000 - 2080.

If time is not given, no time is returned.

If seconds are not included, 00 is added

Any date format is valid as long as a separator is provided, the exception being YYYYMMDD which is valid without a separator.

System format refers to the date format in use by the current user, rather than the default system date format which may be different. This is the same as is returned by the _Now () function.

Example

_DateCalc ("3/4/2005 1:15:01 PM")

Output = 2005/03/04 13:15:01 (assuming system format is M/d/yyyy)

_DateCalc ("3.4.05 13:15", "d.m.yy", "HH:mm:ss")

Output = 2005/04/03 13:15:00

_DateCalc ("20051203", "YYYYMMDD")

Output = 2005/12/03

_DateCalc (_Now ())

Output = _NowCalc () - this can be used as a verification test

DateCalc.au3

Edited by seanhart
Link to comment
Share on other sites

  • 2 years later...

/Blows dust off of the post

I can't believe nobody else has commented on this. After a decent amount of searching in hopes of not having to code this myself, I came across this post. Unless I missed something, it's the only Date/Time calculation that I could find that converts values in arbitrary formats to the AutoIT format so that functions like DateAdd() will work on your otherwise "incompatible" formats. It's awesome! @seanhart, if you're still around, thanks a lot for this, and great job.

The only criticism I have is that I got an error on two lines (28 and 30) for variables being re-declared. Simply commenting out these two lines did the trick, though.

Jeemo

An emoticon is worth a dozen words.

Link to comment
Share on other sites

  • 7 years later...

Do you realize that:

  1. The thread is 10 year old
  2. The post you answered is 7 year old
  3. Its author hasn't been online for 4 years

Please don't resurrect threads this old.

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...