DateAdd doesn't do this for me.
If Date1 is 30 April 2022 then
Code: Select all
DateAdd(Date1, gb.Month, 1)
Is there an elegant way to achieve this?
Gambas 3.17.2
Code: Select all
DateAdd(Date1, gb.Month, 1)
Public Sub Form_Open()
Dim iLoop, iMonth As Integer
Dim iYear As Integer = 2022
Dim dDate As Date
For iLoop = 2 To 13
If iLoop = 13 Then
iYear += 1
iMonth = 1
Else
iMonth = iLoop
End If
dDate = Date(iYear, iMonth, 1) - Day(1)
Print Format(dDate, "dd/mm/yyyy") & " -- " & Format(dDate, "dddd d mmmm yyyy")
Next
End
Result: -what is the purpose of "-Day(1) ?dDate = Date(iYear, iMonth, 1) - Day(1)
Dim dDate As Date
dDate = Date(Now) - Day(1)
Print "Yesterday was " & Format(dDate, "mm/dd/yyyy")
Note that the code in my other posts were using Day/Month/Year format not, as in this example, the USA date format.Dim dDate As Date
dDate = Date(Now) - Day(1)
Print "today Is " & Format(Date(Now), "mm/dd/yyyy")
Print "Yesterday was " & Format(dDate, "mm/dd/yyyy")
Output :Public Sub Form_Open()
Dim dDate As Date
dDate = Date(Now) - Day(2)
Print "today Is " & Format(Date(Now), "mm/dd/yyyy")
Print "Yesterday was " & Format(dDate, "mm/dd/yyyy")
output : Public Sub Form_Open()
Dim dDate As Date
dDate = Date(Now - 1)
Print "today Is " & Format(Date(Now), "mm/dd/yyyy")
Print "Yesterday was " & Format(dDate, "mm/dd/yyyy")
Print "Tomorrow it will be " & Date(Now + 1)
End
results :