Question


IBM
CN
Last activity: 11 Jul 2025 6:45 EDT
convert date to datetime per a specified time zone
how to convert date to datetime (00:00 of that day) per a specified time zone?
e.g. convert "20250711" to HKT (time zone: Asia/Hong_Kong) 00:00 of day 20250711
I know I can use string concatenate to convert "20250711" to "20250711T000000.000 HKT", however want to have a graceful way.
thanks.
-
Reply
-
Share this page Facebook Twitter LinkedIn Email Copying... Copied!


HCA Healthcare
US
To convert a date like "20250711" to a datetime value with time as 00:00 in a specific timezone like Asia/Hong_Kong, you can use Python’s datetime
module. First, use datetime.strptime()
to convert the string "20250711" into a date format. Then, if you are using Python 3.9 or later, you can use zoneinfo.ZoneInfo("Asia/Hong_Kong")
to set the time zone. If you are using an older version of Python, you can use the pytz
module and call .localize()
to apply the time zone. This method is clean and avoids string tricks like manually adding "T000000". The final result will give you the date with time set to midnight (00:00) in the Hong Kong time zone.


IBM
CN
@Sairohith Many thanks.
However, any solution in Pega?


HCLTech
IN
@MaxonL16591286 There is one possible solution but can check once on this as it will be just from UI end, go the property which holds the value of the date, In property 'Display and Validation' option you will have 'UI Control' there you can give 'DateTime-Harness' and it will display the corresponding property in Date and Time, but on clipboard it will be saved as Date only, check if it aligns to your requirement or not.


IBM
CN
Thanks and I prefer to convert date to date time silently in background...
I check available Pega functions and no result.
Updated: 10 Jul 2025 6:28 EDT


HCLTech
IN
@MaxonL16591286 add more to this you can use Pega function FormatdateTime(String dateToconvert,String datePattern, String timeZone, String Locale) you can use it in data transform to covert it example FormatdateTime("20250710T095553.666 GMT","MMMM dd,yy hh:mm","America/New/York", "en_us")


HCLTech
IN
@MaxonL16591286 this is what you can use addTime , it will add time to your date , check more from expression builder
Example- addTime("20250506",0,1,0,0,true,"USDefault")
Updated: 10 Jul 2025 11:41 EDT


IBM
CN
Function addTime like your sample (1st para is a date) returns different result depend on role (operator) under which it's run
e.g. if addTime is run on behalf of an operator, then 1st param, will be converted to 00:00AM of the operator's time zone local time, then add 1 hours per time zone in last param.
however, if addTime is run after Wait wake up, then it run on behalf of an Pega background agent, instead of a real person, which does not had a time zone, so, 1st param will be converted to 00:00AM of GMT then add 1 hours per time zone in last param.
So, same function expression return diff result in diff scenario.
If you are not sure, maybe try to verify.
Thanks.


HCLTech
IN
@MaxonL16591286 parameter value 1 will add 1 hour, you can make it 0 also, i am not sure on operator part as I had tested this in expression builder


IBM
CN
What I mentioned the conversion dependent on operator / role is not adding 1 hour by the param, but a step perform earlier, the 1st param "20250506" is implicitly converted to a date time value first, then next step is to add 1 hour.
This implicitly conversion is operator / role dependency.
When you test in expression builder, the operator / role is always yourself, so the result of the implicitly conversion is always 00:00AM of that day in your time zone, on which 1 hour is added then.
What I am seeking is a method that, I need explicitly convert "20250506" to 00:00AM of that day in a time zone specified by me , instead of depend on current operator / role.


HCLTech
IN
@MaxonL16591286 understood your concern, but i am not sure how to make it generic without considering operator or role


HCLTech
IN
@MaxonL16591286 also can you try this one addTime("20250506",0,0,0,0,true,Default) i saw it will set date time to 20250506T120000.000 GMT