Jump to content

How to get system independent date format


ur
 Share

Recommended Posts

In some systems the date is displayed in the Taskbar as

10-01-2018

And in some systems it is like, 1/10/2018

And in some it is, 10-Jan-2018

And in different formats.

 

I wrote my code to convert 1/10/2018 to 10-01-2018

Func TodaysDate()
    $NewDate = _DateTimeFormat(_NowCalcDate(),1)
    $Array = StringSplit( $NewDate , ',' )
    _ArrayDelete($Array, 0)
    _ArrayDelete($Array, 0)
    $Array1 = StringSplit($Array[0],' ')
    RemoveEmptyArrayLines($Array1)
    ;Will return the present day's date with format dd-mmm-yyyy
    ;$Date =  StringStripWS($Array1[2]&"-"&StringLeft($Array1[1], 3)&"-"&$Array[1], $STR_STRIPALL)
    $Date =  StringStripWS($Array1[2]&"-"&changeDateformat(StringLeft($Array1[1], 3))&"-"&$Array[1], $STR_STRIPALL)
    return $Date
EndFunc

Func RemoveEmptyArrayLines(ByRef $arrLines)
  $intCount = 1
  While $intCount < UBound($arrLines)
         $arrLines[$intCount] = StringStripWS($arrLines[$intCount],$STR_STRIPLEADING + $STR_STRIPTRAILING)
         If StringLen($arrLines[$intCount])=0 Then
            _ArrayDelete($arrLines, $intCount)
            $intCount = $intCount - 1
         EndIf
         $intCount = $intCount + 1
   WEnd
EndFunc


;To convert mmm to mm format
Func changeDateformat($sText)
Local $sMsg = StringStripWS($sText, $STR_STRIPALL)

Switch $sMsg
Case "Jan"
$sMsg = "01"
Case "Feb"
$sMsg = "02"
Case "Mar"
$sMsg = "03"
Case "Apr"
$sMsg = "04"
Case "May"
$sMsg = "05"
Case "Jun"
$sMsg = "06"
Case "Jul"
$sMsg = "07"
Case "Aug"
$sMsg = "08"
Case "Sep"
$sMsg = "09"
Case "Oct"
$sMsg = "10"
Case "Nov"
$sMsg = "11"
Case "Dec"
$sMsg = "12"
EndSwitch

return $sMsg
EndFunc

But again it will work on machines only with 1/10/2018.

Is there any direct function which will give only in the format 10-01-2018, whatever the system settings is.?

I tried all the arguments for _DateTimeFormat, but showing machine dependent settings only.

Google given these two links in AutoIT but these are also for specific formats only,like mine.

 

Please suggest.

Edited by ur
Link to comment
Share on other sites

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

If your use case requires reliable date at all times, be aware that since @MDAY, @MON and @YEAR are 3 distinct macros (hence retrieved sequentially in non-zero time), you might happen to get an invalid or very wrong date (1 day, 1 month and up to 1 year off) if you're unlicky enough to run this code just before midnight.

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

×
×
  • Create New...