ur Posted January 22, 2018 Posted January 22, 2018 I have date in the string format as "DD-MM-YYYY". I need to get yesterday's date from it. I tried converting this from _DateTimeFormat but not working. Is there any direct UDF available to get this.?
jguinch Posted January 22, 2018 Posted January 22, 2018 You have to convert the DD-MM-YYYY format to YYYY/MM/DD, and use it with _DateAdd Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF
ur Posted January 22, 2018 Author Posted January 22, 2018 Oh!! Thanks @jguinch Unnecessarily, I created below logic in the meanwhile. Func yeterdayDate($sDate) $f = StringSplit($sDate,"-");StringSplit("22-01-2018","-") _ArrayDisplay($f) if $f[1]>1 then $f[1]-= 1 Else If Number($f[2])-1 =1 or Number($f[2])=3 or Number($f[2])=5 or Number($f[2])=7 or Number($f[2])=8 or Number($f[2])=10 or Number($f[2])=12 Then $f[1]=31 ElseIf Number($f[2] - 1) < 1 Then $f[1]=31 $f[2]=12 $f[3]=Number($f[3])-1 Else $f[1]=30 EndIf EndIf padZero($f[1]) padZero($f[2]) padZero($f[3]) ;MsgBox(0,"",$f[1]&"-"&$f[2]&"-"&$f[3]) return $f[1]&"-"&$f[2]&"-"&$f[3] EndFunc Func padZero(ByRef $sValue) if Number($sValue)<10 Then $sValue = "0"&Number($sValue) EndIf EndFunc
jguinch Posted January 22, 2018 Posted January 22, 2018 #Include <Date.au3> Local $sDate = "01-01-2018" Local $sDatePreviousDay = _DateAdd("D", -1, StringRegExpReplace($sDate, "(\d{2})[/-](\d{2})[/-](\d{4})", "$3/$2/$1") ) ConsoleWrite($sDatePreviousDay) Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF
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