Convert a string to a date variable and also an additional time variable

Hi guys,

I have the following date/time string format: 05-07-2019 at 09:20am.

How do I extract the date to assign to a variable and also how do I extract the time component too please?

I then would like to use an IF statement to compare the extracted date to Todays date. I’m guessing it will need to be converted to date format in the process too.

1 Like

Fine
If the in_text = “05-07-2019 at 09:20am”
Then
out_date = in_text.ToStringSubString(0,10)
And
out_time = in_text.Split(“at”)(1).ToString.Trim

Where both out_date and out_time is a string variable

Hope this would help you
Cheers @TRX

1 Like

Thanks for the help. I’ve added an additional question to this post also. Do you know how I can then convert the out_date to a date format variable? I also need to convert the new date format variable to todays date using an IF statement.

1 Like

For this
If we are getting out_date as “05-07-2019”

Then in DateTime formate be like
OutDatetime = DateTime.ParseExact(out_text,”dd-MM-yyyy”,System.Globalization.CultureInfo.InvariantCulture)

Where the OutDatetime is a DateTime variable

For this

To get a today’s date
Out_Todaydate = DateTime.Now

Cheers @TRX

1 Like

That works really well! Thanks a lot for all of your help :grinning:

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