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.

@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