Unix Time stamps

Archive of postings to DataStageUsers@Oliver.com. This forum intended only as a reference and cannot be posted to.

Moderators: chulett, rschirm

Locked
admin
Posts: 8720
Joined: Sun Jan 12, 2003 11:26 pm

Unix Time stamps

Post by admin »

I have a field in an input record which is of a standard unix time value. The number of seconds since Jan 1, 1970 12:00:00 am.

Does anyone know of a Oconv/Iconv parameter that would convert this field to Gregorian date and time or of any other efficient third party script that could be used?



--
Michael Feckler mfeckler@onel.com
Minneapolis, MN
952-996-9145
admin
Posts: 8720
Joined: Sun Jan 12, 2003 11:26 pm

Post by admin »

I use these Unix timestamps all the time from one of our source systems. Funny thing is that nowhere in my application do I actually need to convert it. When I did need to do an ad hoc conversion, I always used an SQL expression in Oracle.

Anyway, since you provided me an excuse to write it, here is an expression which converts a Unix timestamp to the DataStage timestamp string. Im not sure what format you really want it in, but this should give you a starting point.

OConv(IConv(1970-01-01,D4-YMD) + Int(UnixTS/86400),D-YMD[4,2,2]):
:OConv(Mod(UnixTS,86400),MTS)

Where "UnixTS" is the Unix timestamp.

-----Original Message-----
From: Michael Feckler [SMTP:mfeckler@onel.com]
Sent: Tuesday, 13 February 2001 3:49
To: informix-datastage@oliver.com
Subject: Unix Time stamps

I have a field in an input record which is of a standard unix time
value. The number of seconds since Jan 1, 1970 12:00:00 am.

Does anyone know of a Oconv/Iconv parameter that would convert this
field to Gregorian date and time or of any other efficient third party
script that could be used?



--
Michael Feckler mfeckler@onel.com
Minneapolis, MN
952-996-9145



*************************************************************************
This e-mail and any files transmitted with it may be confidential and are intended solely for the use of the individual or entity to whom they are addressed. If you have received this e-mail in
error, please notify the sender by return e-mail, and delete this e-mail from your in-box. Do not copy it to anybody else

*************************************************************************
admin
Posts: 8720
Joined: Sun Jan 12, 2003 11:26 pm

Post by admin »

I took a routine written by Mat Ludlam in the uk listed in the Field Initiatives Matrix to do a similar job on minutes since 1800 and changed the code a little.

Produces the same result as Davids using a lot more code.

Steve

*********************************************************************
* Convert the number of minutes since 1/1/1970 12:00:00 to a standard
* time stamp
*
*
Deffun DSRMessage(A1, A2, A3) Calling "DSR_MESSAGE"
Equate TransformName To "UnixDateToJulianDate"

* Define some constants
Equate SecondsInDay To (24 * 60 *60)
Equate SecondsInMinute To 60
*
* Convert 1970 to uniVerse internal format
Internal1970 = ICONV("01/01/1970","D2/")

If Not(Num(Arg1)) Then
ErrorMsg = DSRMessage(-1, "Non-numeric date input %1", Arg1)
Call DSTransformError(ErrorMsg, TransformName)
Ans = "0000-00-00 00:00:00"
GoTo Done:
End

* Break up the number of seconds into days since 1/1/1970 and seconds
* since the start of the day. Makes processing much easier.
NumDays = INT(Arg1/SecondsInDay)
NumSeconds = MOD(Arg1,SecondsInDay)
* Convert the hours to the desired format
TagTime = OCONV(NumSeconds,"MTS")

* Now convert the days to desired format
NumDays = NumDays + Internal1970
TagDate = OCONV(NumDays,"D-YMD[4,2,2]")

* Build the result
Ans = TagDate:" ":TagTime
Done:

****************************************************************************
**********************************************************


Steven Totman email :
Steven.Totman@ascentialsoftware.com
Product Manager cell (us) : 678
641 9522
DataStage Field Initiatives cell (uk) : +44
7887 546461
Ascential Software pager:
1-877-938-5436
Westboro USA email my pager:
8779385436@worldcom.com
MA 01581 (500 Char
Max)

-----Original Message-----
From: David Barham [mailto:David.Barham@Anglocoal.com.au]
Sent: Monday, February 12, 2001 3:46 PM
To: informix-datastage@oliver.com
Subject: RE: Unix Time stamps

I use these Unix timestamps all the time from one of our source systems. Funny thing is that nowhere in my application do I actually need to convert it. When I did need to do an ad hoc conversion, I always used an SQL expression in Oracle.

Anyway, since you provided me an excuse to write it, here is an expression which converts a Unix timestamp to the DataStage timestamp string. Im not sure what format you really want it in, but this should give you a starting point.

OConv(IConv(1970-01-01,D4-YMD) + Int(UnixTS/86400),D-YMD[4,2,2]):
:OConv(Mod(UnixTS,86400),MTS)

Where "UnixTS" is the Unix timestamp.

-----Original Message-----
From: Michael Feckler [SMTP:mfeckler@onel.com]
Sent: Tuesday, 13 February 2001 3:49
To: informix-datastage@oliver.com
Subject: Unix Time stamps

I have a field in an input record which is of a standard unix time
value. The number of seconds since Jan 1, 1970 12:00:00 am.

Does anyone know of a Oconv/Iconv parameter that would convert this
field to Gregorian date and time or of any other efficient third party
script that could be used?



--
Michael Feckler mfeckler@onel.com
Minneapolis, MN
952-996-9145



*************************************************************************
This e-mail and any files transmitted with it may be confidential and are intended solely for the use of the individual or entity to whom they are addressed. If you have received this e-mail in error, please notify the sender by return e-mail, and delete this e-mail from your in-box. Do not copy it to anybody else

*************************************************************************
admin
Posts: 8720
Joined: Sun Jan 12, 2003 11:26 pm

Post by admin »

Have a look in the SDK Transforms, in the Date section.
There are a few there that use "days since 1 Jan 1970" as their basis.

-----Original Message-----
From: Michael Feckler [mailto:mfeckler@onel.com]
Sent: Tuesday, 13 February 2001 04:49
To: informix-datastage@oliver.com
Subject: Unix Time stamps


I have a field in an input record which is of a standard unix time value. The number of seconds since Jan 1, 1970 12:00:00 am.

Does anyone know of a Oconv/Iconv parameter that would convert this field to Gregorian date and time or of any other efficient third party script that could be used?



--
Michael Feckler mfeckler@onel.com
Minneapolis, MN
952-996-9145
Locked