myspacee Posted July 29, 2019 Posted July 29, 2019 Hello, need for a command line script that return what date corresponds to the day of the year. (eg: Today 2019/07/29 is 210th day of year, i need to reverse it ) In this mini-script (compiled as console), Autoit return DOY based on today date #include <Date.au3> Dim $Day1 = @YEAR & "/01/01" If $CmdLine[0] = 0 Then $Days = _DateDiff("D", $Day1, _NowCalcDate() ) ConsoleWrite(StringRight("000" & String($Days + 1), 3)) ElseIf $CmdLine[0] = 1 Then ;///////////////////////// ;// MISS idea/code ;///////////////////////// EndIf In my idea, if I give as parameter Doy Of Year to script, it must return date in this format YYYY/mm/dd (eg: script.exe 210 ---> 2019/07/29) Please, can you help me ? Thank you, m.
BrewManNH Posted July 29, 2019 Posted July 29, 2019 Maybe _DateAdd might be what you're looking for? 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
water Posted July 29, 2019 Posted July 29, 2019 (edited) Use something like this: Add your Day of Year to the _DateToDayValue of 01/01/@YEAR. Then use _DayValueToDate to calculate the date. Edited July 29, 2019 by water My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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
water Posted July 29, 2019 Posted July 29, 2019 _DateAdd seems to have a limitation regarding the initial date: Quote Valid initial date must be between "2000/01/01 00:00:00". and "3000/12/31 23:59:59". My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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
BrewManNH Posted July 29, 2019 Posted July 29, 2019 22 minutes ago, water said: _DateAdd seems to have a limitation regarding the initial date: I was assuming the user wouldn't need a date from the last century. 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
myspacee Posted July 29, 2019 Author Posted July 29, 2019 Brew you are right. I need only referred to this year. Can correct this for me ? #include <Date.au3> Dim $Day1 = @YEAR & "/01/01" If $CmdLine[0] = 0 Then $Days = _DateDiff("D", $Day1, _NowCalcDate() ) ConsoleWrite(StringRight("000" & String($Days + 1), 3)) ElseIf $CmdLine[0] = 1 Then ; Julian date of today. Local $sJulDate = _DateToDayValue(@YEAR, @MON, @MDAY) Local $Y, $M, $D $today_doy = _DateDiff("D", $Day1, _NowCalcDate() ) + 1 if number($today_doy) > number($CmdLine[1]) Then consolewrite("today is after : " & number($today_doy) & "-" & number($CmdLine[1]) & " = " & number($today_doy) - number($CmdLine[1]) & @CRLF) $my_datediff = number($today_doy) - number($CmdLine[1]) $doy_sJulDate = _DayValueToDate($sJulDate - $my_datediff, $Y, $M, $D) consolewrite($doy_sJulDate) Else consolewrite("today is before : " & number($CmdLine[1]) & "-" & number($today_doy) & " = " & number($CmdLine[1]) - number($today_doy) & @CRLF) $my_datediff = number($CmdLine[1]) - number($today_doy) $doy_sJulDate = _DayValueToDate($sJulDate + $my_datediff, $Y, $M, $D) consolewrite($doy_sJulDate) EndIf EndIf IF today is > DOY given, I (_DayValueToDate - DatesDiff) ELSEIF today is < DOY given, I (_DayValueToDate + DatesDiff) This logic is correct ?
BrewManNH Posted July 29, 2019 Posted July 29, 2019 I'd use _DateAdd, it's much simpler. #include <Date.au3> $iDate = 210 ConsoleWrite("Date " & _DateAdd("D", $iDate, @YEAR & "/01/01") & " is " & $iDate & " days from " & @YEAR & "/01/01" & @CRLF) 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
water Posted July 29, 2019 Posted July 29, 2019 (edited) As often the solution depends on what you need/want If you just need YYYY/MM/DD of the calculated date then use ; Calculate the date $sCalculatedDate = _DateDiff("D", $iDOY - 1, @YEAR & "/01/01") ; Is $iDOY before/after/equal to today? If $iDOY < @YDAY Then ConsoleWrite($iDOY & " is before today!" & @CRLF) ElseIf $iDOY > @YDAY Then ConsoleWrite($iDOY & " is after today!" & @CRLF) Else ConsoleWrite($iDOY & " is today!" & @CRLF) EndIf If you - in addition - need to know if the DOY is before/after today then you'll need further calculations. Implemented in my code above. Edited July 31, 2019 by water My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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
Skysnake Posted July 31, 2019 Posted July 31, 2019 There is a problem with what you are trying to do. The problem is Microsoft Windows local environment. PC dates may differ from PC to PC, depending on settings. You should plan and work around this. Consider determining the date independently of the OS. Look at macros and _GUICtrlDTP_SetFormat() @yday ;^^ Good luck Skysnake Why is the snake in the sky?
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