Solved Date Time in Now() not the actual time

madaric

New Member
It's an issue with this, since now will return UTC and your localtime will probably move according to summer/winter time?


Or, based on what I see, you might resolve it with a different approach, like displaying two DateTimes (i.e., 10.01.2018 15:00 DST / 10.01.2018 16:00 CET ) or something like that.
 

Shweta

Active Member
Now() is 2 hours late compared to my local time. What I did was to use "MakeTimeSpan" functionality. Here's how I did it:

Now() + MakeTimeSpan(0,2,0,0)

Please take note that the values are in the order of Day, Hours, Time, Seconds. I hope this helps.

Hi Madraic,

I have a question here.

I have a requirement, wherein I need to convert the DateTime to CET time zone (IST - 4 hours and 30minutes ahead).
I tried like the way you have shared, but I am only getting the date and not the time.

Today()-MakeTimeSpan(0,4,30,0)

Can you please help?

Thanks.
 

Shweta

Active Member
By using Now(), I am not getting the Current Time.. Its giving time something around 5.38 (5 hours 30minutes back from current time).
 

Shweta

Active Member
I got the DateTime by using below expression:

Today() &" "&LocalTime() //stored in variable :GetDateTime

Now, when I am trying to subtract using MakeTimeSpan function, I am getting below error:

Can't subtract from Text

Expression I used: [GetDateTime] - MakeTimeSpan(0,4,30,0)
 

VJR

Well-Known Member
Using Today with LocalTime will yield incorrect results in case it is Monday in one time zone and at the same time it is Sunday in another timezone. So do not use that.

Regarding your earlier post,
Now is giving -5.30 hours because Blue Prism always works in UTC time which is 5.30 hours behind the IST time.

So based on what you want to do:
1. Get Current System Date and Time.
Use Now() and then Add 5.30 hours to it. This will become your Local Date & time.

2. Subtract 4hours 30minutes from that.
Then Subtract 4.30 hours from the above time.
 

Shweta

Active Member
I tried this, and it works fine.

Now() + MakeTimeSpan(0,5,30,0) - MakeTimeSpan(0,4,30,0)

can you please confirm, if you mean this only?
 

VJR

Well-Known Member
I tried this, and it works fine.

Now() + MakeTimeSpan(0,5,30,0) - MakeTimeSpan(0,4,30,0)

can you please confirm, if you mean this only?
Yes I meant the same, and if its working as per your scenario then it should be fine.
Always make it a habit to test it with different scenarios.
 

Emil.Tophoej

New Member
Still missing a smart solution for the summer/winter time shifts.

If you use Now()+timezone-x (you have to know the date for when x shifts - In Denmark it's not the same dates every year)

If you use LocalTime(), there is no way to ensure the correct date around midnight.
 

VJR

Well-Known Member
Hi @Shweta, UTC and IST both do not follow the Daylight Saving Time so you need not worry about those two, but if your original purpose of subtracting the 4.30 hrs was to enter into a different timezone then you will need to consider the daylight saving time changes as suggested by @Emil.Tophoej by checking if that particular timezone follows Daylight Saving (DST) or not.
 

Shweta

Active Member
Hi VJR,

Yes, that timezone follows DST, but not the same dates every year.
Is there any way, I can check for DST and then subtract hours accordingly.

Thanks.
 

VJR

Well-Known Member
Maybe before the beginning of each year you can check the DST start and End dates from website links such as this or if it is not required for too long then perhaps gather a list of future years and maintain it in an Excel sheet.
https://www.timeanddate.com/time/dst/2018.html
or @Emil.Tophoej could give guidelines on how it is used in their project where Denmark time (with DST changes) is to be considered.
 

Emil.Tophoej

New Member
Neat link VJ - then we just need to employ web services for at fully automated DST date xD

I've not yet needed the date and have been utilizing the LocalTime() to keep track of the time.

Another way to get around this is that robots shouldn't get started 00:00 +/- 1h .. Furthermore when robot is started get the starting date and manipulate it if time crosses the 00:00 point. Our most important system updates at night and thereby most robots sleep for a time crossing midnight.

But this does not give the same flexibility and simplicity that a direct LocalDateTime() function (not an actual function) would give.
 

JohanLind

New Member
I just had the same problem and Now()+ LocalTime() - UTCTime() works perfectly. I´m adding date and time to a file that I´m copying to another folder. Just want to add that if you are trying to store the file time in the file name there will be ":" in the text, which is not possible to store. Therefor, my full code is

Replace(Now()+ LocalTime() - UTCTime();":"; "_")

The action Utility - Date and Time Manipulation -> UTC To Local works great as well. Use the Outputs tab in that action to store it in a Data Item. Use Replace() when adding the Data Item in your Copy File action to set the date and time in the file name, without the ":".
 
Last edited:
Top