#### Howdy, Stranger!

It looks like you're new here. Sign in or register to get started.

# First Day of the Month

Member Posts: 339
edited 2008-01-12
Hi
Say, DateX is a date variable holding some unknown date.

How do I find the first day and the last day of the month in that date variable?

TIA

Maluwa
"A bove maiore discit arare minor"-"From the old ox, the young one learns to plow."

• Member, Moderator Posts: 9,031
```datFirstDayOfMonth := DMY2DATE(1,DATE2DMY(datSomeDate,2),DATE2DMY(datSomeDate,3)));
```
Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!

• Member Posts: 8,280
I believe the last day of the month is doing a date calculation with 'CM' as the dateformula. Not sure though, I'd have to verify that.
• Member Posts: 12,562
First day of month is
```FirstDayDate := CALCDATE('<-CM>',MyDate)l
```

And that's all..
Kamil Sacek
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
• Member, Moderator Posts: 9,031
kriki wrote:
```datFirstDayOfMonth := DMY2DATE(1,DATE2DMY(datSomeDate,2),DATE2DMY(datSomeDate,3)));
```

Did see that also the last day of the month was needed:
```datLastDayOfMonth := CALCDATE('<1M>',datFirstDayOfMonth) - 1;
```
Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!

• Member Posts: 12,562
kriki wrote:
kriki wrote:
```datFirstDayOfMonth := DMY2DATE(1,DATE2DMY(datSomeDate,2),DATE2DMY(datSomeDate,3)));
```

Did see that also the last day of the month was needed:
```datLastDayOfMonth := CALCDATE('<1M>',datFirstDayOfMonth) - 1;
```

Or in generaly:

```datLastDayOfMonth := CALCDATE('<CM>',datMyDate);
```

8)
Kamil Sacek
MVP - Dynamics NAV
My BLOG
NAVERTICA a.s.
• Member, Moderator Posts: 9,031
kine wrote:
kriki wrote:
kriki wrote:
```datFirstDayOfMonth := DMY2DATE(1,DATE2DMY(datSomeDate,2),DATE2DMY(datSomeDate,3)));
```

Did see that also the last day of the month was needed:
```datLastDayOfMonth := CALCDATE('<1M>',datFirstDayOfMonth) - 1;
```

Or in generaly:

```datLastDayOfMonth := CALCDATE('<CM>',datMyDate);
```

8)
And with this we are proving there are, most of time, multiple good solutions for the same problem. 8)
Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!

• Member Posts: 3,263
and the last solution, but to many code lines, go over the Day record
Do you make it right, it works too!
• Member Posts: 1
edited 2022-07-01
Please pay attention to use '<CM>', not just 'CM'. 'CM' will throw an error if language is not English))
• Member Posts: 52
Or just DMY2Date(1);