Assign DateTime value directly to Date Time variable

Hi,

Can any one tell me ,

Can we assign DateTime Value to Date Time Variable.
Like

sampleDateTime = “12/02/2020” in assign activity

sampleDateTime is of DateTime datatype.

Thanks in advance.

1 Like

@saritha

Try this.

           sampleDateTime = CDate(“12/02/2020”)
1 Like

dateTimeVariable= Datetime.ParseExact(sampleDateTime,“dd/MM/yyyy”,System.Globalization.CultureInfo.InvariantCulture)

1 Like

Thanks Lakshman,

My question is, does every value is taken as string ?

thanks in advacne

Hi @saritha ,

Ideally, you should ensure that the format is constant throught before converting the variables.

CDate and Convert.ToDateTime doesn’t work with all formats, which is why it is better to play it safe and use:

DateTime.ParseExact("12/02/2020", "dd/MM/yyyy", Nothing)

Kind Regards,
Ashwin A.K

1 Like

sampleDateTime = new datetime(2020, 02, 12)

This set’s the date properly, without any issue around dd/mm or mm/dd formats.
Then when you want to use it use .tostring(“dd/MM/yyyy”) or however you need it.