Populate table data include year months start and end (1 Viewer)

ahmedjamalaboelez

Ahmed J. Aboelez
Local time
Today, 09:12
Joined
Feb 25, 2015
Messages
79
Good day my friends
I have this table in my financial periods details
YearID MonthID MonthStart MonthEnd
2022 01 01/01/2022 31/01/2022
2022 02 01/02/2022 28/02/2022

if i have the first date of the year ( 01/01/2022)
how could i populate 12 Records includes 12 months information same up illustrated data?

I tried this Code its work fine in access ! but not Work with Sql Server !! I think Because of how i calculate start and end date !!!
Code:
Dim rs     As DAO.Recordset
    Set rs = CurrentDb.OpenRecordset("SELECT * FROM fmonth_lines")
    If Not (rs.EOF And rs.BOF) Then
        rs.MoveFirst                              'Unnecessary in this case, but still a good habit
        Do Until rs.EOF = True
            Dim firstdate As String
            firstdate = "01" & "/" & Format(rs!fmonth_id, "00") & "/" & rs!fmonth_fyearid
            rs.Edit
            rs!fmonth_starts = DateSerial(Year(firstdate), month(firstdate), 1)
            rs!fmonth_ends = DateSerial(Year(firstdate), month(firstdate) + 1, 0)
            rs.Update
            rs.MoveNext
        Loop
    Else
    End If
    rs.Close                                   
    Set rs = Nothing
Thanks,
A.J
 

Gasman

Enthusiastic Amateur
Local time
Today, 17:12
Joined
Sep 21, 2011
Messages
14,307
Year() etc work on dates, not strings?

Edit: Well I am blowed :) seems to work? :(

Code:
tt="01/11/2022"
? tt
01/11/2022
? year(tt)
 2022 
? month(tt)
 11 
? day(tt)
 1
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 12:12
Joined
May 21, 2018
Messages
8,529
Even handles regional settings.
?month("01/11/2022")
1
 

ahmedjamalaboelez

Ahmed J. Aboelez
Local time
Today, 09:12
Joined
Feb 25, 2015
Messages
79
00001.png
 

Users who are viewing this thread

Top Bottom