GMT Time

Formally known as "Mercator Inside Integrator 6.7", DataStage TX enables high-volume, complex transactions without the need for additional coding.

Moderators: chulett, rschirm

Post Reply
cschushe
Participant
Posts: 2
Joined: Thu Jun 14, 2007 1:15 pm

GMT Time

Post by cschushe »

Has anyone created a function that returns the current date/time in GMT zone. I had used

GMT=FROMDATETIME( CURRENTDATETIME( ), "{+/-ZZZZ}" )
// Calculate the hour difference between CST and GMT time zone.


=ADDMINUTES( ADDHOURS( CURRENTDATETIME( ), TEXTTONUMBER( MID( GMT, 2, 2 ) ) ), TEXTTONUMBER( MID( GMT, 4, 2 ) ) )


but just learned that the server is in a different country. I can resolve this by taking into account the sign. However I wonder if there is a shortcut?
jgibby
Participant
Posts: 42
Joined: Thu Dec 16, 2004 8:48 am

Post by jgibby »

Try this, it works for me. Note: I am in the Central Time Zone.

Code: Select all

=FROMDATETIME(
   ADDHOURS(
      CURRENTDATETIME()
      ,IF(
         TIMETOTEXT(
            CURRENTDATETIME("{ZZZ}")
         )="CST" // For Central Standard Time
         ,6
         ,5 // Central Daylight Time
      )
   )
   ,"{CCYY/MM/DD HH24:HH:SS}"
)
Actually, this is hacked up from a functional map I created that I reference from other maps so that I don't have to do this manually in each place I need it. The functional map has four input cards and they all are simple text fields as well as the output card. The code is below.

John Gibby

Code: Select all

/*----------------------------------------------------------------------------
REF_Convert_DateTime
This functional map will converting Dates, Times and DateTimes from and to any
of the valid Datastage TX format types.  (See TX Help for "Format Strings").
Additionally, it can perform timezone conversion from GMT to Central Time as
well as from Central Time to GMT.  It also automatically handles Daylight 
Savings Time when performing this conversion using the machine's timezone
settings.  There are four arguments for this functional map:

Argument        TypeTree/Type              Description
DateTimeIn      UTIL_TextField/TextField   Date,Time or DateTime
FromFormat      UTIL_TextField/TextField   Valid TX Format String
ToFormat        UTIL_TextField/TextField   Valid TX Format String
ConversionType  UTIL_TextField/TextField   "+GMT" = To GMT from Local
                                           OR "-GMT" = To Local from GMT
                                           OR "!GMT" = No GMT Conversion
                                           	

Usage Example:
   =REF_Convert_DateTime(
      Value:TypeDef E_373:.:XML              // Date
         + " "                               // Space
         + Value:TypeDef E_337:.:XML         // Time
      ,"{CCYYMMDD HH24MMSS}"                 // Input Format
      ,"{CCYYDDD}"                           // Output Format
      ,"-GMT"                                // GMT to Central
   )

---------------------------------------------------------------------------------*/
=IF(
   WORD(ConversionType,":",1)="!GMT"
   |
   FIND("HH",FromFormat,1)=0
   ,FROMDATETIME(
      TODATETIME(
         DateTimeIn
         ,FromFormat
      )
      ,ToFormat
   )
   ,FROMDATETIME(
      ADDHOURS(
         TODATETIME(
            DateTimeIn
            ,FromFormat
         )
         ,Either(
            IF(
               WORD(ConversionType,":",1)="+GMT"
               ,IF(
                  TIMETOTEXT(
                     CURRENTDATETIME(
                        "{ZZZ}"
                     )
                  )="CST"
                  ,6
                  ,5
               )
            ),IF(
               WORD(ConversionType,":",1)="-GMT"
               ,IF(
                  TIMETOTEXT(
                     CURRENTDATETIME(
                        "{ZZZ}"
                     )
                  )="CST"
                  ,-6
                  ,-5
               )
            ),0
         )
      )
      ,ToFormat
   )
)
"Artificial intelligience is no match for natural stupidity."
Post Reply