DateAdd problem with month end

Post your Gambas programming questions here.
User avatar
grayghost4
Posts: 174
Joined: Wednesday 5th December 2018 5:00am
Location: Marengo, Illinois usa

Re: DateAdd problem with month end

Post by grayghost4 »

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) - 1   ' '  <<<<  this does work 
    Print Format(dDate, "dd/mm/yyyy") & "   --   " & Format(dDate, "dddd d mmmm yyyy")
  Next
 End 
result :
31/01/2022 -- Monday 31 January 2022
28/02/2022 -- Monday 28 February 2022
31/03/2022 -- Thursday 31 March 2022
30/04/2022 -- Saturday 30 April 2022
31/05/2022 -- Tuesday 31 May 2022
30/06/2022 -- Thursday 30 June 2022
31/07/2022 -- Sunday 31 July 2022
31/08/2022 -- Wednesday 31 August 2022
30/09/2022 -- Friday 30 September 2022
31/10/2022 -- Monday 31 October 2022
30/11/2022 -- Wednesday 30 November 2022
31/12/2022 -- Saturday 31 December 2022
User avatar
thatbruce
Posts: 161
Joined: Saturday 4th September 2021 11:29pm

Re: DateAdd problem with month end

Post by thatbruce »

Forget the Day(1) just use, for example
Yesterday = Date(now) - 1
Look at how gambas represents dates internally
Have you ever noticed that software is never advertised using the adjective "spreadable".
Post Reply