• Home
  • Contact
bogge.info

The brain dump of bogge.

  • Contact
  • Blog
    • Computer
    • Food
    • Fun stuff
    • Graphic
    • msi
    • Pirate
      • Scripting
        • AutoIT
        • Crystal syntax
        • Etomite CMS
        • HTML
        • PHP
        • VBScript
    • Software
  • Photo
    • Interior
    • Landscape
    • Nature
    • Sky

Changeing timezone in crystal reports

Posted on July 7, 2011 by bogge

I have a data source that is in UTC (Coordinated Universal Time) and iam in the CET (Central European Time) timezone. So a need too change this time to the relevant timezone so that the data can be understood.

For example if some one is adding a post to the database in 1300 CET, the database says 1200 UTC and when the report is created it says that the post was created 1200 and the reader thinks that this is in CET.

So you can do it litke this:

local datetimevar x:=*Some Date*;
DateTime (YEAR(x), Month(x), day(x), hour(x)+1, minute(x), second(x))

But there is a problem with this approach and that is when is summer time we have Daylight savings so CET (Central European Time) becomes CEST (Central European Summer Time). So CET is +1h to UTC

So a better way to do this is to do it like this:

local datetimevar x:=*Some Date*;
ShiftDateTime (DateTime (YEAR(x), Month(x), day(x), hour(x), minute(x), second(x)), "CET,-60,CEST,0", "")

Explaining the syntax

ShiftDateTime shifts a DateTime value from one time zone to another time zone.

ShiftDateTime (inputDateTime, inputTimeZone, newTimeZone)

inputDateTime: a DateTime value to be shifted.
inputTimeZone: a “TimeZoneString” representing the time zone of the inputDateTime.
newTimeZone: a “TimeZoneString” representing the time zone to which the inputDateTime is shifted

The last empty string in my example indicates the local time zone is taken from the OS settings.

My TimeZoneString is constructed like this:
CET = String name of the standard time zone (eg Central European Time).
-60 = Offset, in minutes, of the standard time zone (CET is -1 hence -60 minutes).
CEST = String name of the DST time zone (eg Central European Summer Time).
0 = Optional DST offset from standard, defaults to one hour ahead of standard offset.

This entry was posted in Crystal syntax, Scripting and tagged crystal report, Crystal syntax, ShiftDateTime, timezone. Bookmark the permalink
  • Connect with us:
  • RSS
  • © 2021 www.bogge.com
  • bogge.com | bogge.eu | bogge.tv