Using RelativeDate to add Hours to an TimeStamp
During recent search I found that some of the posts are requested to add/Subtract Hours from a TimeStamp or manually changing the Time Zones at report Level, unfortunately we do not have a direct way Like AddHours(). So I am explaining below a method that can be useful in such cases.
Let us experiment this using CurrentDate(). Now a simple rule is that When using RelativeDate() function it needs the number of days that you want to add or subtract but, we need for Hours.
So the twist is that if we divide a day in hours we have 24 Hours now if we want x no of hours to be added or Subtracted then we just need to take that part from the day i.e 24 Hrs and add/subtract that form the Current Time.
For e.g. to get 1 Hrs added or subtracted we will take 1 part from 24 which is 1/24 similarly for 2 Hrs it will be 2/24 and so on.
For half hour it would be 0.5/24.
Lets see how it works at report level.
So as you can see we have two columns Current Date & Time and Modified Date & Time. As we can notice that Modified Date & Time is 1 hr behind the Current Date & Time.
Here’s the code how I have handled it at Report Level.
[Current Date & Time]=FormatDate(CurrentDate();”MM/dd/yyyy hh:mm:ss a”)
[Modified Date & Time]=FormatDate(RelativeDate(CurrentDate();-(1/24));”MM/dd/yyyy hh:mm:ss a”)
If you notice the underlined part of Modified Date & Time it shows how we have deducted 1 Hr from the Current Date.
The above method can be useful when you want to convert a Local Time Zone to a different Time Zone at report level.
Please share your valuable inputs and comments if we have a better way to deal with it.