LIST ALL DAYS IN YEAR

User avatar
sal21
PlatinumLounger
Posts: 4353
Joined: 26 Apr 2010, 17:36

LIST ALL DAYS IN YEAR

Post by sal21 »

I'm not sure of this code...
my dubt is based on Febrary...

anno=2026

Code: Select all

Sub ListDaysInMonth()

    Dim iMonth As Integer
    Dim iYear As Integer
    Dim FirstDayOfMonth As Date
    Dim LastDayOfMonth As Date
    Dim dDate As Date, K As Integer

    iMonth = 1
    iYear = ANNO
    K = 1

    FirstDayOfMonth = DateSerial(iYear, iMonth, 1)
    LastDayOfMonth = DateSerial(iYear, 12 + 1, 0)

    For dDate = FirstDayOfMonth To LastDayOfMonth
        GIORNO = UCase(Format(dDate, "DDDD"))
        SQL = "INSERT INTO CALENDARIO (GIORNI, GIORNO, NR) VALUES ('" & dDate & "', '" & GIORNO & "', '" & K & "')"
        CON.Execute SQL, , adCmdText + adExecuteNoRecords
        K = K + 1
    Next

End Sub

User avatar
HansV
Administrator
Posts: 78446
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: LIST ALL DAYS IN YEAR

Post by HansV »

It will handle February correctly. Your variables FirstDayOfMonth and LastDayOfMonth are actually the first day and last day of the year, not of a month.
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4353
Joined: 26 Apr 2010, 17:36

Re: LIST ALL DAYS IN YEAR

Post by sal21 »

:clapping:
HansV wrote:
09 Sep 2022, 15:36
It will handle February correctly. Your variables FirstDayOfMonth and LastDayOfMonth are actually the first day and last day of the year, not of a month.
PLEASE...
eXPLAIN ME the part of dateserial format...

.Text = Format(DateSerial(ANNO, M, D), "short date")

note:
googling

User avatar
SpeakEasy
4StarLounger
Posts: 548
Joined: 27 Jun 2021, 10:46

Re: LIST ALL DAYS IN YEAR

Post by SpeakEasy »

https://docs.microsoft.com/en-us/office ... plications

Go to the 'Named date/time formats' section

User avatar
HansV
Administrator
Posts: 78446
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: LIST ALL DAYS IN YEAR

Post by HansV »

And see DateSerial function.

"short date" is the Short Date format set on your computer in the Region control panel. In Italy, it probably looks like "27/09/2022".
"long date" is the Long Date format set in the Region Control panel. It might look like "27 settembre 2022", or perhaps "martedi 27 settembre 2022".
Best wishes,
Hans

User avatar
sal21
PlatinumLounger
Posts: 4353
Joined: 26 Apr 2010, 17:36

Re: LIST ALL DAYS IN YEAR

Post by sal21 »

HansV wrote:
09 Sep 2022, 18:21
And see DateSerial function.

"short date" is the Short Date format set on your computer in the Region control panel. In Italy, it probably looks like "27/09/2022".
"long date" is the Long Date format set in the Region Control panel. It might look like "27 settembre 2022", or perhaps "martedi 27 settembre 2022".
clear!
tks