How to get Date, Time and Time Zone in Report Footer using Cube View Extender Rule.

Radhika
New Contributor

Hi , We are trying to achieve the below format of Date ,Time and Time Zone in Cube View report footer 

25/08/2023 5:00:00PM CT/IST/ET 

Radhika_0-1692971306037.png

 

Here, time zone should vary according to user's local timing.

Any solutions on this are greatly appreciated.

Thanks 

 

3 REPLIES 3

SStalker
New Contributor III

I do not believe there are any built in calls to get user time zone.  Account Rec has each user store their local time zone in a user setting table due to this.

RobbSalzmann
Valued Contributor

The following will give you a date time group with the three letter Time Zone designation:
25/08/2023 5:00:00PM CDT 

Dim currentDateTime As DateTime = DateTime.Now
Dim formattedDateTime As String = currentDateTime.ToString("dd/MM/yyyy h:mm:ss tt") 
Dim regex As New Regex("\b\w")
Dim tz As String = String.Concat(regex.Matches(TimeZoneInfo.Local.StandardName).Cast(Of Match)().Select(Function(m) m.Value))
return $"{formattedDateTime} {tz}"

Note: timezone information returned is based on the runtime environment of the OS server.
If you store your User's time zone ids in a table, you can use the following to get the correct date and time for their TZ:

Dim targetTimeZoneId As String = "Central Standard Time" ' Replace with the desired timezone ID, e.g., "Central Standard Time"
Dim targetTimeZone As TimeZoneInfo = TimeZoneInfo.FindSystemTimeZoneById(targetTimeZoneId)
Dim currentDateTime As DateTime = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, targetTimeZone)
Dim formattedDateTime As String = currentDateTime.ToString("dd/MM/yyyy h:mm:ss tt") 
Dim regex As New Regex("\b\w")
Dim tz As String = String.Concat(regex.Matches(targetTimeZoneId).Cast(Of Match)().Select(Function(m) m.Value))

return $"{formattedDateTime } {tz}"

JackLacava
Community Manager
Community Manager

As others mentioned, I don't think we can know a user location, but you can look up the user Culture (there is a property on the SI object), make an assumption (i.e. if the culture is de-DE, the user will probably be in Germany) and calculate their local time accordingly.