LAE

Welcome to the LAE community!  Please feel free to start a discussion in the discussion tab or join in a conversation.

Discussions

Members

Resources

Events

 View Only
  • 1.  Date formats

    Employee
    Posted 12-08-2010 09:53

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: joygupta

    Hi,

    I have a date in string format "12-Jan-10".

    I want to convert it to a date type column but retain the same format:


    override emit 'PTT_ORDER_DATE'.date("D-m-YY") as "PTT_ORDER_DATE"

    I get error when i write "DD-m-YY" ..says cannot parse so "D-m-YY" BUT
    this returns

    "2010-01-12"

    Can someone help?
    Thanks.


  • 2.  RE: Date formats

    Employee
    Posted 12-10-2010 05:45

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: Tim Meagher

    Hi,

    The format: D-m-YY

    Specifies a 1-2 digit day, followed by a 3 character month name followed by a 2-digit year.

    If the fields do all have 2 digit days, then DD-m-YY should work, but my guess is that you have some fields with things like:
    1-Jan-10
    i.e. with a 1-digit day.
    Therefore, the "DD" part won't work because it requires a 2-digit day field.

    The output of this is then a date.
    Dates are always displayed as CCYY-MM-DD.

    Therefore, 12-Jan-10 is being parsed as the 12th January 2010, which is then displayed as 2010-01-10 - which seems correct.

    Note that while the date format is displayed in CCYY-MM-DD format, they are stored internally as a binary date format.
    There is no way (to my knowledge) to change the way a date field is displayed.

    If you want this to be displayed in a different manner, you will need to convert to a string object, at which point you are free to format them however you want.

    For example, if you wanted to display the date as a String, formatted with 2 digit days, followed by 2 digit months, followed by the year (all separated with "/" characters), then you could use something like:

    dateField = 'dateField'.date("D-m-YY")
    dateFieldAsString = format("%02d",dateField.day())+"/"+format("%02d",dateField.month())+"/"+dateField.year()
    
    emit dateFieldAsString as "DateStringField"
    Does this help?


  • 3.  RE: Date formats

    Employee
    Posted 12-13-2010 09:45

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: joygupta

    Thanks this explains a lot!

    --Joy


  • 4.  RE: Date formats

    Employee
    Posted 11-10-2014 18:50

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: Leaner

    Hi,

    Four years later, is this still the best way of doing this?

    If so, when I try to run it, I am getting this error:
    WARN: Expect string or unicode argument
    		Line: 1; BrainScript: dateField = 'DateOfBirth'.date("D-m-YY")
    		Operator: 'date'
    Error Code: brain.node.ToDate_ExprOp.cpp.119
    
    ERROR: Node execution terminated while processing data by error:
    Expect string or unicode argument
    Error Code: lae.node.executionTerminated
    So I converted the field to a string, then I get this error:
    WARN: invalid parameters to operator day: string 
    		Line: 2; BrainScript: dateFieldAsString = format("%02d",dateField.day())+"/"+format("%02d",dateField.month())+"/"+dateField.year()
    		Operator: 'day'
    Error Code: brain.node.ExprUtils.h.286
    
    ERROR: Node execution terminated while initializing expert output by error:
    invalid parameters to operator day: string 
    Error Code: lae.node.executionTerminated
    I've been trying to get a date format to come out as 01/12/1970.

    Any help would be appreciated


  • 5.  RE: Date formats

    Employee
    Posted 11-10-2014 19:20

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: Leaner

    Found a quick way of getting the date to output in any format one would like: http://community.lavastorm.com/threa...amp-convertion

    What I have are dates in a datestamp format, so I had to switch it up:
    v = 'DateOfBirth'.str() #pickup value from input column
    v = v.replace("-","/") #change space to slash
    s = v.split("/") #split into an array
    
    day = s.getItem(2).long()
    month = s.getItem(1).long()
    year = s.getItem(0).long()
    d = strcat(day+"/"+month+"/"+year)
    
    DateOfBirth = d.str()
    
    override emit DateOfBirth as "DOB"
    Any better ways?

    Ta.


  • 6.  RE: Date formats

    Employee
    Posted 11-10-2014 21:48

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: stonysmith

    What datatype is the column DateOfBirth on the input?
    If it is already a date or dateTime data type you should not have to use the date() conversion.


  • 7.  RE: Date formats

    Employee
    Posted 11-12-2014 02:53

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: Leaner

    The datatype is 'date' which is why I was converting it to 'string' (as posted originally) but am still getting an error.

    That's why I went with the other solution of just slicing the string into variables.


  • 8.  RE: Date formats

    Employee
    Posted 11-12-2014 04:40

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: stonysmith

    Try this:
    dateFieldAsString = format("%02d/%02d/%04d",DateOfBirth.day(),DateOfBirth.month()),DateO fBirth.year())