Extracting month,day, and year from the date

Hi everyone,

I have a date variable (currently set to generic value). It is pulling data from excel and typing into pdf form. In excel it reads mm/dd/yyyy format. But on the pdf form, it needs the month, day, and year in separate boxes. I tried datevariable.ToString(“mm”) for month but it only types “mm” onto the pdf. Any ideas? Do I need to change the variable type?

Thanks

To get month from your Datetime variable you should call .ToString(“MM”) in capitals to call month numbers.

Day and year are both lower case. - “dd” and “yyyy”

3 Likes

Still didn’t work, it just typed “MM” into the pdf field

You will need to convert the value into a datetime variable then before extracting the information

DateTimeVariable = Datetime.Parse(datevariable)
You can then use DateTimeVariable.ToString(“MM”)

4 Likes

I was thinking, if you already have a string you can split it on basis of / and then use the values 0,1,2 respectively
IF you are going to have to covert etc. because you want a string value, not necessarily a date.

I used DateTime.Parse(datevariable).ToString(“MMMM”) and it worked. Thanks!

7 Likes

Yes, I have extracted in string datatype only.
Thanks

1 Like

Thankyou, that works for me.

try dis it worked for me

DateTime.Parse(date_val).Month.ToString()
DateTime.Parse(date_val).Month
DateTime.Parse(date_val).Month.ToString(“MM”)

if u need day or year replace above Month value with day or year