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.  Emit new field with any date in any given month converted to 1st day of that month

    Employee
    Posted 12-18-2014 17:15

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

    Originally posted by: mrbigglesdotnet

    Hi there,

    I have a date column with dates in DD-MM-YYYY format over a number of months and years. I need to create a new column that returns the same month and year of the original date but replaces any day date with 01. That is, the new date column will be 01-MM-YYYY. This new date column will then allow me to histogram by MM-YYYY.

    e.g.

    Date New Date
    12-12-2014 01-12-2014
    23-06-2013 01-06-2013
    12-10-2012 01-10-2012

    I've tried the following code in a filter node but neither of them work.

    Attempt 1
    Response_Month = Response_dt.str(date(year(Response_dt),month(Respo nse_dt),"01"))
    emit * , Response_Month

    Attempt 2
    Response_Month = Response_dt.date(year(Response_dt),month(Response_ dt),"01")
    emit * , Response_Month

    Is anyone able to help? Thanks.


  • 2.  RE: Emit new field with any date in any given month converted to 1st day of that month

    Employee
    Posted 12-18-2014 19:39

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

    Originally posted by: stonysmith

    So close...

    Response_Month = Response_dt.date(year(Response_dt),month(Response_dt),1)
    in this form, the date() function is expecting numbers
    x=date(year,month,day)
    x=date(2014,12,25)

    You had put "01", and that's a string, not a number.


  • 3.  RE: Emit new field with any date in any given month converted to 1st day of that month

    Employee
    Posted 12-19-2014 06:07

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

    Originally posted by: mrbigglesdotnet

    Thanks for the speedy response! Unfortunately when I use the advised code, I recieve the following error:

    WARN: operator takes 0-3 parameters, not 4
    Line: 1; Brainscript: Response_Month = Response_dt.date(year(Response_dt),month(Response_ dt),1)
    Operator: 'date'
    Error Code: brain.node.ToDate_ExprOp.cpp.51

    ERROR: Node execution terminated while processing data by error:
    operator takes 0-3 parameters, not 4
    Error Code: lae.node.executionTerminated

    I've checked Response_dt is identified by Lavastorm as "date" and not "string".

    Does it matter that the date in Response_dt is actually in YYYY-MM-DD format?


  • 4.  RE: Emit new field with any date in any given month converted to 1st day of that month

    Employee
    Posted 12-19-2014 06:30

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

    Originally posted by: stonysmith

    My bad..
    Response_Month = date(year(Response_dt),month(Response_dt),1)


  • 5.  RE: Emit new field with any date in any given month converted to 1st day of that month

    Employee
    Posted 12-19-2014 07:07

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

    Originally posted by: mrbigglesdotnet

    Mate, sensational! It works a treat. Thanks