_Vlad Posted April 5, 2020 Share Posted April 5, 2020 Hello AutoIt, From a while I try to build a copy function of _Date_Diff(). At the moment this function does not work properly as it need to have a custom format of the date. So, if I want for example to calculate the difference of days between my pc date and current day, I can't cause it need to have the same format. There is a function built for that already? Or we should start to build one, I find this really important. :) Thank yoU! Link to comment Share on other sites More sharing options...
jchd Posted April 5, 2020 Share Posted April 5, 2020 28 minutes ago, _Vlad said: From a while I try to build a copy function of _Date_Diff(). At the moment this function does not work properly as it need to have a custom format of the date. I guess you mean _DateDiff() instead. This function doesn't use what you call a "custom format". It processes the only computational format for string datetime (ISO). Convert the date strings to the ISO format and _DateDiff() will work for you. ; _DateDiff() works with yyyy/mm/dd as well as with yyyy-mm-dd dates ConsoleWrite(_DateDiff("D", "2020-03-26", _NowCalcDate()) & @LF) _Vlad 1 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 hereRegExp tutorial: enough to get startedPCRE 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 More sharing options...
Aelc Posted April 6, 2020 Share Posted April 6, 2020 (edited) #include <Date.au3> $start = @MDAY & "." & @MON & "." & @YEAR $end = "31.10.2020" MsgBox ( 64,"",_calc_month(1,$start,$end) & " Days" & @CRLF & _calc_month(2,$start,$end) & " Months" & @CRLF & _calc_month(3,$start,$end) & " Years") Func _calc_month($return_mode = "1",$Startdate = "01.01.2000", $Enddate = "29.02.2000") $Startdatecache = GUICtrlRead($Startdate) If $Startdatecache = 0 Then Else $Startdate = $Startdatecache EndIf $Enddatecache = GUICtrlRead($Enddate) If $Enddatecache = 0 Then Else $Enddate = $Enddatecache EndIf Local $Days = StringTrimRight($Startdate, 8) Local $Month = StringTrimRight($Startdate, 5) $Month = StringTrimLeft($Month, 3) Local $year = StringTrimLeft($Startdate, 6) Local $Days2 = StringTrimRight($Enddate, 8) Local $Month2 = StringTrimRight($Enddate, 5) $Month2 = StringTrimLeft($Month2, 3) Local $year2 = StringTrimLeft($Enddate, 6) $DateCalc = _DateDiff('d', $year & "/" & $Month & "/" & $Days, $year2 & "/" & $Month2 & "/" & $Days2) Switch $return_mode Case 1 $DIFF = $DateCalc Case 2 $DIFF = Round($DateCalc / (365 / 12), 1) Case 3 $DIFF = Round ( $DateCalc / 365,3 ) EndSwitch Return $DIFF EndFunc ;==>_calc_month i wrote this a long time ago because i had problems with that formats too. all i wanted was to input a normal date format and a normal end format 18 hours ago, _Vlad said: So, if I want for example to calculate the difference of days between my pc date and current day, I can't cause it need to have the same format. Actually the pc date is the current day date in scripts hope that helps didn't change that but maybe you ll do. i just started to code at this time where it was written. today i should rewrite it but i didn't need this again. better would be a Stringregexp() there i would say also you can work without the Switch and Round.. if you just adjust the _datediff('d') with other types just look into the helpfile of it greetings Edited April 6, 2020 by Aelc _Vlad 1 why do i get garbage when i buy garbage bags? Link to comment Share on other sites More sharing options...
jchd Posted April 6, 2020 Share Posted April 6, 2020 Horrific code (sorry). Date/time should only be stored in a computational format: Unix epoch, ISO string, Julianday, JulianDate, and the like. Cleverly convert the chosen internal format from/to human locale for input/output. 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 hereRegExp tutorial: enough to get startedPCRE 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 More sharing options...
Aelc Posted April 6, 2020 Share Posted April 6, 2020 1 minute ago, jchd said: Horrific code (sorry). that's what i meant with he should rewrite it. well the think behind was to change the format to display it on labels and so on so why i would i want to have a computational code then? why do i get garbage when i buy garbage bags? Link to comment Share on other sites More sharing options...
jchd Posted April 6, 2020 Share Posted April 6, 2020 Then you don't need that much code! BTW, concatenating @YEAR, @MONTH, @DAY blindly is dangerous. 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 hereRegExp tutorial: enough to get startedPCRE 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 More sharing options...
mikell Posted April 6, 2020 Share Posted April 6, 2020 27 minutes ago, Aelc said: all i wanted was to input a normal date format "normal" is a very relative and subjective concept BTW usually a simple preliminary conversion using example #2 of StringRegExpReplace (helpfile) does the job $end = "31.10.2020" $end = StringRegExpReplace($end, '(\d{2})\.(\d{2})\.(\d{4})', '$3/$2/$1') Msgbox(0,"", $end) Link to comment Share on other sites More sharing options...
jchd Posted April 6, 2020 Share Posted April 6, 2020 "Normal" is indeed very relative: https://help.talend.com/reader/f7_Igxda4W5myTdc5yN2xw/OdzUMuVkKkL4x~h6zp36~A 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 hereRegExp tutorial: enough to get startedPCRE 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 More sharing options...
Aelc Posted April 6, 2020 Share Posted April 6, 2020 @mikell Yes thats what i said below the Code. Didn't you read it completly? Again this was one of my first Scripts which i didn't change. I already made porposals to improve it e.g. with stringregexp ... why do i get garbage when i buy garbage bags? Link to comment Share on other sites More sharing options...
Aelc Posted April 6, 2020 Share Posted April 6, 2020 @jchd "Normal" for me how I wanted to Display it. Of course there are so much more Formats. Seems like you just want to correct me instead of bringing a Solution. why do i get garbage when i buy garbage bags? Link to comment Share on other sites More sharing options...
argumentum Posted April 6, 2020 Share Posted April 6, 2020 16 hours ago, _Vlad said: I can't cause it need to have the same format #include <APILocaleConstants.au3> #include <WinAPILocale.au3> Local $iID = _WinAPI_GetUserDefaultLCID() ConsoleWrite('Language => ' & _WinAPI_GetLocaleInfo($iID, $LOCALE_SLANGUAGE) & @CRLF) ConsoleWrite('Date format => ' & _WinAPI_GetLocaleInfo($iID, $LOCALE_SSHORTDATE) & @CRLF) ConsoleWrite('Time format => ' & _WinAPI_GetLocaleInfo($iID, $LOCALE_STIMEFORMAT) & @CRLF) ConsoleWrite('Currency name => ' & _WinAPI_GetLocaleInfo($iID, $LOCALE_SNATIVECURRNAME) & @CRLF) ConsoleWrite('Monetary symbol => ' & _WinAPI_GetLocaleInfo($iID, $LOCALE_SCURRENCY) & @CRLF) Post that information so that we can have a clue. Or maybe with the above it solved your need. And if it did, post the solution. _Vlad 1 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 6, 2020 Moderators Share Posted April 6, 2020 _Vlad, You might find my Date_Time_Convert UDF (the link is in my sig) useful as it allows you to convert from and to any format you wish. M23 _Vlad 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
_Vlad Posted April 6, 2020 Author Share Posted April 6, 2020 I'm back, thank you all for the answers! The script I wrote it turns out to be complex and hard to understand as I didn't knew about some functions posted above. In the end, it seems that @Melba23 already have a script for that, better than the one that I was currently working at. Until I will be capable to post something ingenious I still have to study further :)) Thanks one more time everyone! argumentum 1 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 6, 2020 Moderators Share Posted April 6, 2020 _Vlad, Glad I could help. M23 _Vlad 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
BrewManNH Posted April 7, 2020 Share Posted April 7, 2020 16 hours ago, _Vlad said: In the end, it seems that @Melba23 already have a script for that, He usually does. mikell, _Vlad and Melba23 1 2 If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now