DigDeep Posted July 28, 2017 Posted July 28, 2017 I have 2 sections here. 1st portion is the correct format I need in mm/dd/yyyy. But I would like to simplify the 2nd portion instead of writing multiple lines.along with getting the date format in MM/DD/YYYY. Local $File = FileGetTime(FilePatch) Local $sNewDate1 = $File[1] & "/" & $File[2] & "/" & $File[0] ; Changing the format as mm/dd/yyyy Local $sJulDate = _DateToDayValue(@YEAR, @MON, @MDAY) Local $Y, $M, $D $sJulDate = _DayValueToDate($sJulDate, $Y, $M, $D) $GetDate = $M & "/" & $D & "/" & $Y ;~ MsgBox(0, "", $GetDate) ; Today ; ===>>> Can we siplify this to get the Date format in MM/DD/YYYY Local $Yesterday1 = _DateAdd('d', -1, _NowCalcDate()) ; Yesterday Local $Yesterday2 = _DateAdd('d', -2, _NowCalcDate()) ; 2 days ago Local $Yesterday3 = _DateAdd('d', -3, _NowCalcDate()); 3 days ago $aYesterday = StringSplit($Yesterday1, "/") $sYesterdayFormatted1 = $Yesterday1[2] & "/" & $Yesterday1[3] & "/" & $Yesterday1[1] $aYesterday = StringSplit($Yesterday2, "/") $sYesterdayFormatted2 = $Yesterday2[2] & "/" & $Yesterday2[3] & "/" & $Yesterday2[1] $aYesterday = StringSplit($Yesterday3, "/") $sYesterdayFormatted3 = $Yesterday3[2] & "/" & $Yesterday3[3] & "/" & $Yesterday3[1] ; ===>>> Can we siplify this to get the Date format in MM/DD/YYYY If $sNewDate1 = $GetDate Or $sNewDate1 = $sYesterdayFormatted1 Or $sNewDate1 = $sYesterdayFormatted2 Or $sNewDate1 = $sYesterdayFormatted3 Then ; FileDate is either today or less than 3 days then it's fine. MsgBox(0, '', 'Pass') Else MsgBox(0, '', 'Fail') EndIf
mikell Posted July 29, 2017 Posted July 29, 2017 12 hours ago, DigDeep said: ; FileDate is either today or less than 3 days then it's fine. Why don't you compare using _DateDiff ? Local $File = FileGetTime(FilePatch) Local $sFileDate = $File[0] & "/" & $File[1] & "/" & $File[2] If _DateDiff("D", $sFileDate, _NowCalcDate()) > 3 Then MsgBox(0, '', 'Fail') Danp2 1
Danp2 Posted July 29, 2017 Posted July 29, 2017 Local $sJulDate = _DateToDayValue(@YEAR, @MON, @MDAY) Local $Y, $M, $D $sJulDate = _DayValueToDate($sJulDate, $Y, $M, $D) $GetDate = $M & "/" & $D & "/" & $Y Mikell has given you the solution, but I just had to ask about this code. Couldn't this have just been written with a single line? $GetDate = @MON & "/" & @MDAY & "/" & @YEAR Latest Webdriver UDF Release Webdriver Wiki FAQs
DigDeep Posted July 29, 2017 Author Posted July 29, 2017 Thanks @mikell... I was trying out the same but wasn't able to align the format correctly. I can use your's as per needed. Thanks @Danp2 too for giving your time. I tried your suggestion prior mikell replied. But that was going a little long to have less than 7 days. But I think I can utilize your's way too with something else I have in future.
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