Date Functions in Datastage

Reading Time: 4 minutes
For a timestamp, the format is %yyyy-%mm-%dd %hh:%nn:%ss. If extended to include microseconds, the format is %yyyy-%mm-%dd %hh:%nn:%ss.x, where x gives the number of decimal places seconds is given to
For a date, the format is %yyyy-%mm-%dd
CurrentDate()Use this function to add a new column containing the date to the data output by the Transformer stage
CurrentTime()Use this function to add a new column containing the time to the data output by the Transformer stage
CurrentTimeMS()Use this function to add a new column containing the time to the data output by the Transformer stage. You must set the Extended field in the column metadata to Microseconds to contain the full time
CurrentTimestamp()Use this function to add a new column containing the timestamp to the data output by the Transformer stage
CurrentTimestampMS()Use this function to add a new column containing the timestamp to the data output by the Transformer stage. You must set the Extended field in the column metadata to Microseconds to contain the full timestamp
DateFromDaysSince(-1,”1958-08-18″)If mylink.mynegintcol contains the integer -1, and mylink.mydatecol contains the date 1958–08–18, then the following three functions are equivalent, and return the date 1958–08–17
DaysSinceFromDate(“1958-08-18″,”2008-08-18”)If mylink.mysourcedate contains the date 1958–08–18 and mylink.mygivendate contains the date 2008–08–18, then the two following functions are equivalent, and return the integer value 18263
DateOffsetByComponents(“2011-08-18”, 2011, 8, 18)If mylink.basedate contains 2011-08-18 and mylink.yearos contains the value 2, mylink.monthos contains the value 0, and mylink.dayofmonthosol contains the value 0, then the two following functions are equivalent, and return the date 2013–08–18
DateFromComponents(2010, 12, 2)If mylink.yearcol contains the value 2010, mylink.monthcol contains the value 12, and mylink.dayofmonthcol contains the value 2, then the two following functions are equivalent, and return the date 2010–12–02
DateFromJulianDay(2454614)If mylink.myjulcol contains the value 2454614, then the two following functions are equivalent, and return the date 2008–05–27.
JulianDayFromDate(“2008–05–27”)If mylink.mydate contains the date 2008–05–27, then the two following functions are equivalent, and return the value 2454614
DaysInMonth(“1958-08-18”)If mylink.mysourcedate contains the date 1958–08–18, then the two following functions are equivalent, and return the integer value 31
DaysInYear(“2012-08-18”)If mylink.mysourcedate contains the date 2012–08–18, then the two following functions are equivalent, and return the integer value 366
DateOffsetByDays(“2011-08-18”, 2)If mylink.basedate contains 2011-08-18 and mylink.dayoffset contains the value 2, then the two following functions are equivalent, and return the date 2011–08–20
HoursFromTime(“22:30:00”)If mylink.mytime contains the time 22:30:00, then the following two functions are equivalent, and return the integer value 22
MinutesFromTime(“22:30:52”)If mylink.mytime contains the time 22:30:52, then the two following functions are equivalent, and return the value 30
SecondsFromTime(“22:30:52”)If mylink.mytime contains the time 22:30:52, then the two following functions are equivalent, and return the value 52
YearweekFromDate(“2008-08-18”)If mylink.mydate contains the date 2008-08-18, then the two following functions are equivalent, and return the value 33:
YeardayFromDate(“2008-08-18”)If mylink.mydate contains the date 2008-08-18, then the two following functions are equivalent, and return the value 231
MonthDayFromDate(“2008-08-18”)If mylink.mydate contains the date 2008-08-18, then the two following functions are equivalent, and return the value 18
WeekdayFromDate(“2008-08-18”)If mylink.mydate contains the date 2008-08-18, then the two following functions are equivalent, and return the value 1:
MonthFromDate(“2008-08-18”)If mylink.mydate contains the date 2008-08-18, then the two following functions are equivalent, and return the value 8
YearFromDate(“2008-08-18”)If mylink.mydate contains the date 2008-08-18, then the two following functions are equivalent, and return the value 2008:
NextWeekdayFromDate(“2008-08-18”, “thursday”)If mylink.mysourcedate contains the date 2008-08-18, then the two following functions are equivalent, and return the value 2008–08–21
PreviousWeekdayFromDate(“2008-08-18”, “thursday”)If mylink.mysourcedate contains the date 2008-08-18, then the two following functions are equivalent, and return the value 2008–08–14
NthWeekdayFromDate(“2009-08-18”, “thursday”, 1)Returns first thrusday after the date mentioned.
If mylink.mydate contains the date 2009-08-18, then the two following functions are equivalent, and return the value 2009–08–27
SecondsSinceFromTimestamp(“2008–08–18 22:30:52″,”2008–08–19 22:30:52”)If mylink.mytimestamp contains the timestamp 2008–08–18 22:30:52, and mylink.mytimestamp_base contains the timestamp 2008–08–19 22:30:52, then the two following functions are equivalent, and return the value -86400