How get the first month of the invoice date

Hi team,

I need to take the first month of the invoice date
Example: input:- 10/24/2021
Output:- 01/24/2021

Can anyone help me to do this.

Thanks
Chethan P

@copy_writes

Try below expression.

Input = “10/24/2021”

           Output = "01/"+CDate("10/24/2021").ToString("dd/")+CDate("10/24/2021").ToString("yyyy")
1 Like

Hi,

If your input is String type and you want to get result as String type, the following works.

"01"+yourDateString.Substring(yourDateString.IndexOf("/"))

If your input is DateTime type and you want to get result as DateTime type, the following works.

New DateTime(yourDateTime.Year,1,yourDateTime.Day)

Regards,

1 Like

Hi @Yoichi @lakshman
Thanks for the answers both solution is work but @lakshman can you please Explain why you are using CDate what it do in the code and Y we need to use two times CDate(“10/24/2021”)

Regards
Chethan P

Hi,

FYI, if you want to use CDate, simpley the following will work.

CDate(yourDateString).ToString("01/dd/yyyy")

Regards,

1 Like

@copy_writes

CDate method will convert String type to Date format.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.