Champak Posted October 17 Share Posted October 17 (edited) I'm grabbing the name of a file, which is the date and time, and setting it to the modified date. The problem is it is the date gets set properly but the time doesn't...it's off by -1hr, and I'm verifying it beforehand. The input format varies as 2022-02-02_083224_P.jpg ----- YYYY-MM-DD_HHMMSS Func _Set_File_Dates($sFileSelect) $aDirContent_New = StringSplit($sFileSelect, "|", 2) For $i = UBound($aDirContent_New) - 1 to 0 Step - 1 $FileNameDate = StringSplit($aDirContent_New[$i], "\", 2) $aFileNameDate = StringSplit($FileNameDate[UBound($FileNameDate)-1], "_", 2) $NewTime = $aFileNameDate[0] & $aFileNameDate[1] $NewTime = StringRegExp($NewTime, "\d+", 3) _ArrayDisplay($NewTime) $NewTime = $NewTime[0] & $NewTime[1] & $NewTime[2] MsgBox(0,"new date", $NewTime) FileSetTime ( $aDirContent_New[$i], $NewTime, $FT_MODIFIED) Next ;Exit EndFunc Any help? Edited October 17 by Champak Link to comment Share on other sites More sharing options...
pixelsearch Posted October 17 Share Posted October 17 4 hours ago, Champak said: the date gets set properly but the time doesn't...it's off by -1hr It has been discussed in this thread, good luck. Musashi, TheXman and ioa747 3 Link to comment Share on other sites More sharing options...
ioa747 Posted October 17 Share Posted October 17 (edited) expandcollapse popup;#include <Array.au3> #include <FileConstants.au3> ;~ The input format varies as 2022-02-02_083224_P.jpg ----- YYYY-MM-DD_HHMMSS $sFileSelect = @ScriptDir & "\2022-02-02_083225_R.jpg|" & @ScriptDir & "\2022-03-02_083224_P.jpg" _Set_File_Dates($sFileSelect) Func _Set_File_Dates($sFileSelect) $aDirContent_New = StringSplit($sFileSelect, "|", 2) For $i = UBound($aDirContent_New) - 1 To 0 Step -1 $FileNameDate = StringSplit($aDirContent_New[$i], "\", 2) ConsoleWrite("File=" & $aDirContent_New[$i] & @CRLF) $aFileNameDate = StringSplit($FileNameDate[UBound($FileNameDate) - 1], "_", 2) ConsoleWrite("$aFileNameDate[0]=" & $aFileNameDate[0] & @CRLF) ConsoleWrite("$aFileNameDate[1]=" & $aFileNameDate[1] & @CRLF) $NewDate = StringReplace($aFileNameDate[0], "-", "") ConsoleWrite("$NewDate=" & $NewDate & @CRLF) $Hour = StringLeft($aFileNameDate[1], 2) $Minute = StringMid($aFileNameDate[1], 3, 2) $Second = StringRight($aFileNameDate[1], 2) ; Adjust DST hour $Hour = StringFormat("%02i", Number($Hour) + 1) ; Combine date and time in the format "YYYYMMDDHHMMSS" $FinalDateTime = $NewDate & $Hour & $Minute & $Second ConsoleWrite("$FinalDateTime:" & $FinalDateTime & @CRLF) ConsoleWrite("FileSetTime=" & FileSetTime($aDirContent_New[$i], $FinalDateTime, $FT_MODIFIED) & @CRLF) ConsoleWrite("" & @CRLF) Next ;Exit EndFunc ;==>_Set_File_Dates Edited October 17 by ioa747 I know that I know nothing Link to comment Share on other sites More sharing options...
IronFine Posted October 18 Share Posted October 18 2 hours ago, ioa747 said: $Hour = StringFormat("%02i", Number($Hour) + 1) Better use _DateAdd, as just adding 1 hour might cause problems, when the hour is 23. ioa747 1 Link to comment Share on other sites More sharing options...
ioa747 Posted October 18 Share Posted October 18 thanks for the suggestion It is also quite problematic since it cannot understand whether the entered date is summer or winter time. I thought that I would manage it with a small correction, but it was not so simple since the DST date is not fixed and every year is different. so the best solution (easiest) is the one he indicated pixelsearch in the link Musashi 1 I know that I know nothing Link to comment Share on other sites More sharing options...
Champak Posted October 18 Author Share Posted October 18 Thanks all. ioa747 1 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