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.  Pull date out of string

    Employee
    Posted 05-28-2014 12:08

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

    Originally posted by: johnvvu

    The following brainscript results in the three columns (attached image). How do I pull the date out of each file from 'File' into the format of yyyy-mm-dd into a column of its own.

    a = 'FileName'.split("/")
    file = a[len(a)-1]
    biller = a[len(a)-2]
    emit *
    emit file as File
    emit biller as Biller
    Attachments:
    image.jpg


  • 2.  RE: Pull date out of string

    Employee
    Posted 05-28-2014 13:01

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

    Originally posted by: ltolleson

    You almost have it... Just pull the date from the 'File' field as a string and convert it to a date. Then take the date variable fd and use the year, month, and day functions to format it however you want.

    a = 'FileName'.split("/")
    file = a[len(a)-1]
    biller = a[len(a)-2]
    fd= file.substr(file.strFind("_") + 1, 8).date("MM-DD-CCYY")
    filedate = fd.year() + "-" + fd.month() + "-" + fd.day()


    emit *
    emit file as File
    emit biller as Biller
    emit filedate


  • 3.  RE: Pull date out of string

    Employee
    Posted 05-29-2014 04:27

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

    Originally posted by: johnvvu

    That works, thank you.

    Also, the fifth line formats the month as a single digit; how could I format May as 05?


  • 4.  RE: Pull date out of string

    Employee
    Posted 05-29-2014 05:59

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

    Originally posted by: dsc88dsc88

    If you wanted to have the date in the LAE date format (CCYY-MM-DD), then you could just use fd

    If you wanted the date to be in a string format (with zeros included) as CCYY-MM-DD, you could use the following:
    filedate = strcat(fd.str().left(4),"-",fd.str().left(7).right(2),"-",fd.str().right(2))

    Or if you wanted the date to be in a string format (with zeros included) as CCYY-DD-MM, you could use the following:
    filedate = strcat(fd.str().left(4),"-",fd.str().right(2),"-",fd.str().left(7).right(2))

    etc, etc


  • 5.  RE: Pull date out of string

    Employee
    Posted 05-29-2014 06:19

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

    Originally posted by: ejones

    Originally posted by: johnvvu
    					

    That works, thank you.

    Also, the fifth line formats the month as a single digit; how could I format May as 05?
    You can convert the month to the name of the month by using an array of the month names.

    if firstExec then { # if first record in input
    # We only need to put a value in this list variable once
    monthList = list("ThereIsNoZeroMonth","January"
    ,"Febuary","March","April"
    ,"May","June","July","August","September"
    ,"October","November","December")
    }
    # then use that list when you want the name corresponding to the number
    month = "05" # you started with this
    monthNumber = month.int() # you need it to be a number type
    monthName = monthList.getItem(monthNumber)
    emit monthName as MonthName

    Since month names that you would want vary by the location and context, you'll have to create the array with the months spelled the way you want.


  • 6.  RE: Pull date out of string

    Employee
    Posted 05-29-2014 06:33

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

    Originally posted by: ltolleson

    John,

    The easiest way to make a 1 digit day or month into 2 digits is to use the "pad(2)" function. This will by default add zeros to the left of any string less than 2 characters.

    Look at the help for the pad() function. There are parameters for number of characters, character to pad, and direction.


    See example below...


    a = 'FileName'.split("/")
    file = a[len(a)-1]
    biller = a[len(a)-2]
    fd= file.substr(file.strFind("_") + 1, 8).date("MM-DD-CCYY")
    filedate = fd.year() + "-" + fd.month().pad(2) + "-" + fd.day().pad(2)


    emit *
    emit file as File
    emit biller as Biller
    emit filedate


  • 7.  RE: Pull date out of string

    Employee
    Posted 05-29-2014 07:14

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

    Originally posted by: johnvvu

    Thanks for various ways to do this,
    John