date to string conversion

Stimulsoft Reports.NET discussion
Post Reply
ddsmith99301
Posts: 52
Joined: Wed May 17, 2017 10:14 pm

date to string conversion

Post by ddsmith99301 »

I am trying to convert a date to a string. Any help will be appreciated. Here is what I tried but didn't work.

This is the expression I used in a text box.
{(DateSerial(Year(Today), Month(Today) + 1, 0)).ToString("MM.dd.yyyy")}
Lech Kulikowski
Posts: 6254
Joined: Tue Mar 20, 2018 5:34 am

Re: date to string conversion

Post by Lech Kulikowski »

Hello,

Your expression is incorrect: month - 13 and day - 0.
Please use
{(DateSerial(Year(Today), Month(Today), 1)).ToString("MM.dd.yyyy")}

Thank you.
ddsmith99301
Posts: 52
Joined: Wed May 17, 2017 10:14 pm

Re: date to string conversion

Post by ddsmith99301 »

Thank you so much for replying during this holiday season. I have a project deadline of this coming Friday and I am scrambling to get it done on time.
Someone gave that as a way to find the end of the month. I guess they didn't realize that December wouldn't work.

Here is my solution for the end of the current date's month.
{(DateSerial(Year(Today), Month(Today) ,DaysInMonth(Year(Today),Month(Today)))).ToString("MM.dd.yyyy")}
And for two months earlier. Unfortunately, this only works if the Month is greater than 2.
{(DateSerial(Year(Today), Month(Today) - 2,DaysInMonth(Year(Today),Month(Today) - 2))).ToString("MM.dd.yyyy")}
Lech Kulikowski
Posts: 6254
Joined: Tue Mar 20, 2018 5:34 am

Re: date to string conversion

Post by Lech Kulikowski »

Hello,

Please try to use:
{DateSerial(Year(Today), Today.AddMonths(-2).Month, DaysInMonth(Year(Today),Today.AddMonths(-2).Month)).ToString("MM.dd.yyyy")}

Thank you.
ddsmith99301
Posts: 52
Joined: Wed May 17, 2017 10:14 pm

Re: date to string conversion

Post by ddsmith99301 »

I have a little correction. This is how I got it to work.

DateSerial(Year(Today).AddMonths(-2), Today.AddMonths(-2).Month, DaysInMonth(Year(Today),Today.AddMonths(-2).Month)).ToString("MM/dd/yyyy")
Lech Kulikowski
Posts: 6254
Joined: Tue Mar 20, 2018 5:34 am

Re: date to string conversion

Post by Lech Kulikowski »

Hello,

Thank you for the information.
Post Reply