Need Calendar Help
Need Calendar Help
Has anyone written a routine to find the day before the current date? In other words, if it's April 3rd, 2004, I need a routine that give me April 2nd, 2004. This needs to handle such issues as leap years, months with 31, 30, or 28 days, etc.
Thanks,
Alex
Thanks,
Alex
"How is it possible to bring order out of memory? I should like to begin at the beginning, patiently, like a weaver at his loom. I should like to say, 'This is the place to start, there can be no other.'
-Beryl Markham
-Beryl Markham
Re: Need Calendar Help
Code: Select all
today=Date()
yesterday=AddDate(today,#PB_Date_Day,-1)
Debug FormatDate("%dd-%mm-%yyyy",yesterday)
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
"PureBasic won't be object oriented, period" - Fred.
Re: Need Calendar Help
Cool! Thankyou!
Alex
Alex
PB wrote:Code: Select all
today=Date() yesterday=AddDate(today,#PB_Date_Day,-1) Debug FormatDate("%dd-%mm-%yyyy",yesterday)
"How is it possible to bring order out of memory? I should like to begin at the beginning, patiently, like a weaver at his loom. I should like to say, 'This is the place to start, there can be no other.'
-Beryl Markham
-Beryl Markham
-
TerryHough
- Enthusiast

- Posts: 781
- Joined: Fri Apr 25, 2003 6:51 pm
- Location: NC, USA
- Contact:
@TerryHough: Need some more info first -- if today was Friday, does that
mean you want to get next Friday's date, or two Friday's later?
Edit: Anyway, here's what I have for now:
mean you want to get next Friday's date, or two Friday's later?
Edit: Anyway, here's what I have for now:
Code: Select all
today=Date() : friday=today
; Next line gets this Friday's date.
Repeat : friday=AddDate(friday,#PB_Date_Day,1) : check=DayOfWeek(friday) : Until check=5
friday=AddDate(friday,#PB_Date_Day,7) ; Now get the next Friday after the one just found.
Debug "Today is "+FormatDate("%dd-%mm-%yyyy",today)
Debug "Two Fridays away is "+FormatDate("%dd-%mm-%yyyy",friday)
Last edited by PB on Mon Apr 10, 2006 10:17 pm, edited 1 time in total.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
"PureBasic won't be object oriented, period" - Fred.
Re: Need Calendar Help
@Fred: This example...
...leads me to request that AddDate be renamed to something like CalcDate
instead, as we're not always adding to the date at all. What do you think?
Code: Select all
yesterday=AddDate(today,#PB_Date_Day,-1)
instead, as we're not always adding to the date at all. What do you think?
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
"PureBasic won't be object oriented, period" - Fred.
-
TerryHough
- Enthusiast

- Posts: 781
- Joined: Fri Apr 25, 2003 6:51 pm
- Location: NC, USA
- Contact:
Try this one Terry...
Code: Select all
#Friday = 5
Procedure GetSecondFriday(xDate)
dow = DayOfWeek(xDate)
If dow < #Friday
secondFriday = AddDate(xDate, #PB_Date_Day, 7 + (#Friday - dow))
Else
secondFriday = AddDate(xDate, #PB_Date_Day, 14 - (dow - #Friday))
EndIf
ProcedureReturn secondFriday
EndProcedure
checkDate = Date(2006, 4, 10, 0, 0, 0)
checkDate$ = FormatDate("%mm/%dd/%yyyy", checkDate)
MessageRequester("Second Friday from " + checkDate$ + " will be", FormatDate("%mm/%dd/%yyyy", GetSecondFriday(checkDate)))
What goes around comes around.
PB 5.21 LTS (x86) - Windows 8.1
PB 5.21 LTS (x86) - Windows 8.1
-
TerryHough
- Enthusiast

- Posts: 781
- Joined: Fri Apr 25, 2003 6:51 pm
- Location: NC, USA
- Contact:
Thanks Sparkie!
Here is what I am using, includes features of yours and PB's and a bit
more efficient than either.
Thanks guys.
Terry
Here is what I am using, includes features of yours and PB's and a bit
more efficient than either.
Code: Select all
SecondFriday = AddDate(Date(),#PB_Date_Day,9)
dow = DayOfWeek(SecondFriday)
If dow - 5 ; Computed date is not a Friday
SecondFriday = AddDate(SecondFriday, #PB_Date_Day,(5 - dow)) ; Adjust to following Friday
EndIf
MessageRequester("Debug","The second Friday after today is " +FormatDate("%mm-%dd-%yyyy",SecondFriday),0)
Terry
@TerryHough: Mine was just a quick rush job before I left for work (that's
why I said I need more info first). But when I got home, Sparkie had posted
a better one, so I just didn't bother fixing mine.
why I said I need more info first). But when I got home, Sparkie had posted
a better one, so I just didn't bother fixing mine.
I compile using 5.31 (x86) on Win 7 Ultimate (64-bit).
"PureBasic won't be object oriented, period" - Fred.
"PureBasic won't be object oriented, period" - Fred.
-
TerryHough
- Enthusiast

- Posts: 781
- Joined: Fri Apr 25, 2003 6:51 pm
- Location: NC, USA
- Contact:

