Loc Posted June 7, 2021 Share Posted June 7, 2021 May I ask: 1 month has 30 days, it will show 0month30day and continue 30 days as 1Month30day How can I display it like that? Link to comment Share on other sites More sharing options...
FrancescoDiMuro Posted June 7, 2021 Share Posted June 7, 2021 (edited) 9 minutes ago, Loc said: 1 month has 30 days Don't tell February or it gets mad P.S.: post what you've tried Edited June 7, 2021 by FrancescoDiMuro Click here to see my signature: Spoiler ALWAYS GOOD TO READ: Forum Rules Forum Etiquette Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 7, 2021 Moderators Share Posted June 7, 2021 Loc, If you want any number of days to be displayed as "months" of 30 day periods and then the remainder, you need to use Int and Mod - like this: $iPeriod = 38 $iMonthLength = 30 $iMon = Int($iPeriod / $iMonthLength) $iDays = Mod($iPeriod, $iMonthLength) ConsoleWrite($iMon & ":" & $iDays & @CRLF) M23 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...
Loc Posted June 7, 2021 Author Share Posted June 7, 2021 8 hours ago, FrancescoDiMuro said: Don't tell February or it gets mad P.S.: post what you've tried My point is just an example for me to follow. from 8/4/2021 - 8/6/2021 is 60 days instead of showing 60 days I want to show 1 month and 30 days past today it is 2 months 0 days and every day like that, the day part will be added 1 until the end of the 30th it will be 1 month and the day will be 0 Link to comment Share on other sites More sharing options...
JockoDundee Posted June 8, 2021 Share Posted June 8, 2021 11 hours ago, Loc said: 8/4/2021 - 8/6/2021 is 60 days In the U.S. it’s 2 days FrancescoDiMuro 1 Code hard, but don’t hard code... Link to comment Share on other sites More sharing options...
Loc Posted June 8, 2021 Author Share Posted June 8, 2021 12 minutes ago, JockoDundee said: In the U.S. it’s 2 days $iPeriod = 38 $iMonthLength = 30 $iMon = Int($iPeriod / $iMonthLength) $iDays = Mod($iPeriod, $iMonthLength) ConsoleWrite($iMon & ":" & $iDays & @CRLF) Replace the $iPeriod variable of the M23 with _DateDiff! Link to comment Share on other sites More sharing options...
Skysnake Posted June 9, 2021 Share Posted June 9, 2021 If you have the time and inclination, have a look at SQL support for data arithmetic. SQLite is easily implemented and can return all these answers. Skysnake Why is the snake in the sky? Link to comment Share on other sites More sharing options...
Malkey Posted June 9, 2021 Share Posted June 9, 2021 This method has more accuracy than a 30 days a month method. #include <Date.au3> Local $sStartDate = "8/4/2021" ; Format is "D/M/YYYY", not US date format. Local $sEndDate = "9/6/2021" ; Format is "D/M/YYYY", not US date format. Local $sStart = _DateConvert($sStartDate, 0) Local $sEnd = _DateConvert($sEndDate, 0) ConsoleWrite("$sStart = " & $sStart & ' in format "YYYY/MM/DD"' & @CRLF) ConsoleWrite("$sEnd = " & $sEnd & ' in format "YYYY/MM/DD"' & @CRLF) Local $iNumMnths = _DateDiff('M', $sStart, $sEnd) ; Number of months between dates. Local $sStartPlusMnths = _DateAdd("M", $iNumMnths, $sStart) ; $sStartDatePlusMnths = Start Date plus number of months between dates. Local $iRemDays = _DateDiff('D', $sStartPlusMnths, $sEnd) ; Number of remaining days. Local $iTotalDays = _DateDiff('D', $sStart, $sEnd) ; Total number of days between dates. ConsoleWrite("(" & $iNumMnths & " month" & ($iNumMnths = 1 ? " " : "s ") & _ $iRemDays & " day" & ($iRemDays = 1 ? ")" : "s)") & " or " & _ $iTotalDays & " days" & @CRLF) ; ============== _DateConvert ================= ; If $US = 1 then format of $Date is in "[M]M/[D]D/YYYY" otherwise, ; If $US = 0 then format of $Date is in "[D]D/[M]M/YYYY" (not US date format) ; The converted Date out has format "YYYY/MM/DD" (for use in _Date...() AutoIt UDFs) ; Func _DateConvert($Date, $US = 1) Local $aTemp = StringSplit($Date, "/") Return StringFormat("%4i/%02i/%02i", $aTemp[3], ($US ? $aTemp[1] : $aTemp[2]), ($US ? $aTemp[2] : $aTemp[1])) EndFunc ;==>_DateConvert #cs ; Returns:- $sStart = 2021/04/08 in format "YYYY/MM/DD" $sEnd = 2021/06/09 in format "YYYY/MM/DD" (2 months 1 day) or 62 days #ce ; Returns:- Gianni 1 Link to comment Share on other sites More sharing options...
Gianni Posted June 10, 2021 Share Posted June 10, 2021 this _ElapsedTime() function returns the elapsed time between 2 dates in a 3 elements array expressed in years, months, days (no error checking implemented) #include <Date.au3> Local $Start = "1962/05/02" ; start date Local $Stop = _NowCalcDate() ; end date Local $aElapsed = _ElapsedTime($Start, $Stop) MsgBox(0, "Elapsed Time", $aElapsed[0] & " years, " & $aElapsed[1] & " months, " & $aElapsed[2] & " days") ; returns the elapsed time between 2 dates expressed in years, months, days Func _ElapsedTime($sStartDate, $sEndDate) Local Enum $iYears, $iMonths, $iDays Local $aResult[3] ; $aResult[$iYears] = _DateDiff('Y', $sStartDate, $sEndDate) $aResult[$iMonths] = _DateDiff('M', _DateAdd('Y', $aResult[$iYears], $sStartDate), $sEndDate) $aResult[$iDays] = _DateDiff('D', _DateAdd('M', $aResult[$iMonths], _DateAdd('Y', $aResult[$iYears], $sStartDate)), $sEndDate) Return $aResult ; [0] years; [1] months; [2] days EndFunc ;==>_ElapsedTime Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
Loc Posted June 11, 2021 Author Share Posted June 11, 2021 13 hours ago, Chimp said: Hàm _ElapsedTime () này trả về thời gian đã trôi qua giữa 2 ngày trong mảng 3 phần tử được biểu thị bằng năm, tháng, ngày (không thực hiện kiểm tra lỗi) #include <Date.au3> $ Start địa phương = "1962/05/02" ; ngày bắt đầu Local $ Stop = _NowCalcDate ( ) ; ngày cuối Local $ aElapsed = _ ElapsedTime ( $ Start , $ Stop ) MsgBox ( 0 , "Thời gian đã trôi qua" , $ aElapsed [ 0 ] & "years", & $ aElapsed [ 1 ] & "months" & $ aElapsed [ 2 ] & "days" ) ; trả về thời gian đã trôi qua giữa 2 ngày được biểu thị bằng năm, tháng, ngày Func _ ElapsedTime ( $ sStartDate , $ sEndDate ) Local Enum $ iYears , $ iMonths , $ iDays Local $ aResult [ 3 ] ; $ aResult [ $ iYears ] = _DateDiff ( 'Y' , $ sStartDate , $ sEndDate ) $ aResult [ $ iMonths ] = _DateDiff ( 'M' , _DateAdd ('Y' , $ aResult [ $ iYears ] , $ sStartDate ) , $ sEndDate ) $ aResult [ $ iDays ] = _DateDiff ( 'D' , _DateAdd ( 'M' , $ aResult [ $ iMonths ] , _DateAdd ( 'Y' , $ aResult [ $ iYears ] , $ sStartDate ) ) , $ sEndDate ) Trả về $ aResult ; [0] năm; [1 tháng; [2] ngày EndFunc ; ==> _ ElapsedTime Thanks for the above suggestions. I usually use the date format Day Months Year Link to comment Share on other sites More sharing options...
Luke94 Posted June 11, 2021 Share Posted June 11, 2021 #include <String.au3> ConsoleWrite(_FormatDate('25/12/2020')) Func _FormatDate($sDate) Local $aDate = StringSplit($sDate, '/', $STR_NOCOUNT) If @ERROR Then Return -1 EndIf If UBound($aDate) = 3 Then Return StringFormat('%04s/%02s/%02s', $aDate[2], $aDate[1], $aDate[0]) EndIf Return -1 EndFunc Output: Quote 2020/12/25 Combined with @Chimp's function: #include <String.au3> #include <Date.au3> ;ConsoleWrite(_FormatDate('25/12/2020')) Local $Start = _FormatDate("02/05/1962") ; start date *dd/mm/yyyy Local $Stop = _NowCalcDate() ; end date Local $aElapsed = _ElapsedTime($Start, $Stop) ;~ MsgBox(0, "Elapsed Time", $aElapsed[0] & " years, " & $aElapsed[1] & " months, " & $aElapsed[2] & " days") ; Years, Months, Days MsgBox(0, "Elapsed Time", $aElapsed[2] & " days, " & $aElapsed[1] & " months, " & $aElapsed[0] & " years") ; Days, Months, Years ; returns the elapsed time between 2 dates expressed in years, months, days Func _ElapsedTime($sStartDate, $sEndDate) Local Enum $iYears, $iMonths, $iDays Local $aResult[3] ; $aResult[$iYears] = _DateDiff('Y', $sStartDate, $sEndDate) $aResult[$iMonths] = _DateDiff('M', _DateAdd('Y', $aResult[$iYears], $sStartDate), $sEndDate) $aResult[$iDays] = _DateDiff('D', _DateAdd('M', $aResult[$iMonths], _DateAdd('Y', $aResult[$iYears], $sStartDate)), $sEndDate) Return $aResult ; [0] years; [1] months; [2] days EndFunc ;==>_ElapsedTime Func _FormatDate($sDate) Local $aDate = StringSplit($sDate, '/', $STR_NOCOUNT) If @ERROR Then Return -1 EndIf If UBound($aDate) = 3 Then Return StringFormat('%04s/%02s/%02s', $aDate[2], $aDate[1], $aDate[0]) EndIf Return -1 EndFunc 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