Converting Now to UK time, and String to DateTime

Hi all

This is part of my process I’m trying to figure out:

  1. Obtain when the process was last run by referring back to a datetime variable (dtLastRun) which had Now assigned to it (this would be done at the end of the last run of the process)
  2. Download a spreadsheet, work through the column where the survey date is featured, saving the variable as strSurveyTime
  3. Work out if the survey was returned since the process was last run

Issues I’m having:

  1. The dtLastRun is in the American format, i.e. today is 09/05/2023 16:21:12 but the dtLastRun is bringing back 05/09/2023 16:21:12. How would I change this into the UK format?
  2. The strSurveyTime is bringing back the UK format, i.e. 09/05/2023 16:21:12 and is a string format. How can I convert the string into a DateTime variable?

Thanks :slight_smile:

DateTime.ParseExact(strDate, "MM/dd/yyyy HH:mm:ss", CultureInfo.InvariantCulture).toString("dd/MM/yyyy HH:mm:ss")


Hope this may help you


1 Like

Hi @Short

Please try the following expression for your use case:

dtLastRun = DateTime.ParseExact(dtLastRun.ToString("MM/dd/yyyy HH:mm:ss"), "MM/dd/yyyy HH:mm:ss", CultureInfo.InvariantCulture).ToString("dd/MM/yyyy HH:mm:ss")

Hope this helps,
Best Regards.

1 Like

Hi @Srini84 :slight_smile:

Thanks for getting back to me so quickly.

DateTime.ParseExact(strDate, “MM/dd/yyyy HH:mm:ss”, CultureInfo.InvariantCulture).toString(“dd/MM/yyyy HH:mm:ss”)

With this, it looks like it’s converting to string so would I still be able to compare the time passed between dtLastRun and dtSurveyTime? (Cdate(yourStringFormat) worked so I’m now using the datetime variable instead of strSurveyTime, thank you!)

Hi @Short ,

Maybe also check with the below Expression :

DateTime.Parse("09/05/2023 16:21:12",new System.Globalization.CultureInfo("en-GB"))


1 Like

Hi @arjunshenoy

With this, it looks like it’s converting to string so would I still be able to compare the time passed between dtLastRun and dtSurveyTime?

Hi @supermanPunch

Thanks for the response :slight_smile:

That looks like it’s converting the time to string, will I still be able to work out the difference between the dates?


@Short ,

It is in the DateTime type and not a String.

The date and time will always change though, so I can’t quote manually 09/05/2023 16:21:12 in it and it isn’t working with a variable

@Short ,

Is it possible for you to showcase what you have implemented or tested ?

And we should also be able to use a variable in place of the String value used.

Showcasing of visual implementation and testing done would get rid of the confusions that are present and would allow us to correct our/your findings faster.

Hi @supermanPunch

Apologies, for some reason one of my work laptops won’t let me upload pictures from it to the Forum, I’ve had to faff around and email the screenshots to my other one.

So I’ve tried someone else’s suggestion of using CDate(strVariable) to convert Now into DateTime but I get this error:

With the converting the date cell in Excel to DateTime isn’t working either, this is what it’s picking up:


And this is it after I’ve used your code:

Any ideas?

@Short ,

Was this not the Expected result ? From the Output Panel, we do see that the format is changed.


So it originally picked it up in the correct format (SurveyTime org) but when I’ve converted it into a DateTime variable (dtSurveyTime, the second of the write lines) it’s converted back to the US format. It needs to be in DateTime variable format because I need to compare it to another DateTime variable to see if the survey was received after a certain time

Hi @Short

For Comparing Now UK Time: UTC+1:00 and String that you receive from Excel:

you can create 2 variables:
NowTime: DateTime.UtcNow.AddHours(1).ToString(“dd/MM/yyyy hh:mm:ss”)
ExcelDateTime: DateTime.Parse(strSurveyTime,new System.Globalization.CultureInfo(“en-GB”))

and compare both of them in an if activity.


@Short ,

Is it possible for you to show the other DateTime variable and value in the Output Panel by logging as well ?

We’ll be able to compare the values better.

Hi @adiijaiin

Just tried that:

It’s still converting back to US formatting when changing to a DateTime variable :confused:

Hi @supermanPunch

I’m trying to change the Now.ToString(“dd/MM/yyyy hh:mm:ss”) to a DateTime variable but it’s not recognising today’s date as a valid date as there’s no 16th month

Hi @Short ,

I see that they both are coming in different formats,
But if you wanna compare them to each other, can you try that once?

I think so that you’ll be able to compare them.


@Short ,

If the other date Time variable that you want to compare is the current Date, then you don’t need to convert it String. You can use it as Now itself.

You can perform the Comparison in the below way :

DateTime.Parse(strSurveyTime,new System.Globalization.CultureInfo("en-GB")).Date.Equals(Now.Date)

If strSurveyTime is not the Current Date, then the above Expression will return as False.

Check the below as well :

Hi @supermanPunch

The first time I run my process, I’ll create the dtNow variable. At the end of the process, I’ll assign a dtLastRun = dtNow so the next time I run the process, I can pick up the dtSurveyTime from the Excel and see if the survey was received after the dtLastRun, so it won’t just be looking at the date it’ll be comparing the time too. Hope that makes sense!

I thought it would be quite easy haha but now I’m finding it a struggle