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 Conversion Issue

    Employee
    Posted 07-06-2012 11:08

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

    Originally posted by: Kathleen McGuigan

    Hi,
    I am trying to convert a date into a string format of CCYYMMDD (no slashes or dashes). The input is MM/DD/CCYY (i.e. 2/4/2010). I was able to convert this format to a date field in the graph but cannot manage to get it in the required format for the output (i.e 20100204).

    Any help would be appreciated. Thanks.
    Kathleen


  • 2.  RE: Date Conversion Issue

    Employee
    Posted 07-06-2012 11:25

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

    Originally posted by: stonysmith

    try this:
    emit outfield = 'inputfield'.date("MM/DD/CCYY").str().replace("-","")

    another (longer) version is this:
    x = 'inputfield'.date("MM/DD/CCYY")
    emit outfield = format("%04d%02d%02d",year(x),month(x),day(x))


  • 3.  RE: Date Conversion Issue

    Employee
    Posted 07-06-2012 11:53

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

    Originally posted by: Kathleen McGuigan

    Thanks Stony, I'm still getting an error.

    Here is some sample data from the input file.
    TN maxPortDate
    4045555555 2/4/2011
    4045555555 3/7/2012
    4045555555 2/23/2011
    4045555555 12/11/2010

    It is coming from a csv file. Thanks.
    Kathleen


  • 4.  RE: Date Conversion Issue

    Employee
    Posted 07-06-2012 12:55

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

    Originally posted by: stonysmith

    use

    'inputfield'.date("M/D/CCYY").

    If you check the help for the date() function, MM requires 2 digits.. M allows either one or two. Same for DD vs D

    If your dates are in multiple different formats, you can do something like this:

    x=date(null) # no valid date format found
    if isDate('inputfield',"CCYYMMDD") then x = 'inputfield'.date("CCYYMMDD")
    else if isDate('inputfield',"MMDDCCYY") then x = 'inputfield'.date("MMDDCCYY")
    else if isDate('inputfield',"M/D/CCYY") then x = 'inputfield'.date("M/D/CCYY") #handles 1 and 2 digit day and month
    else if isDate('inputfield',"M-D-CCYY") then x = 'inputfield'.date("M-D-CCYY")
    else if isDate('inputfield',"CCYY/M/D") then x = 'inputfield'.date("CCYY/M/D")
    else if isDate('inputfield',"CCYY-m-D") then x = 'inputfield'.date("CCYY-m-D") # lowercase m supports 'Jan','Feb', etc.
    else if isDate('inputfield',"D-m-CCYY") then x = 'inputfield'.date("D-m-CCYY")
    else if isDate('inputfield',"D m CCYY") then x = 'inputfield'.date("D m CCYY")
    emit outputfield = x