This topic contains 4 replies, has 3 voices, and was last updated by  lev 3 years, 6 months ago.

Modifying dateparse with new date format

  • I have a customer who is sending a date in AL1.6 in hte format mmddYYYY. The dateparse module throws an error, because when it sees the date ‘01262011’, it believes ’11’ is the day, and it tells me that isn’t possible. I wanted to put this format into the list of “common formats”, as such in line 11:

    local known_fmts = {}
    if true then
       local templates = {
          -- HL7 Standard
          -- Common formats (US)
          'm/d/yy[yy][ H:MM[:SS][ tt][ ZZZ]]',
          'yyyy-m-d[ w][ H:MM[:SS][ tt][ ZZZ]]',
          '[dddd, ]mmmm d[w], yyyy[ H:MM[:SS][ tt][ ZZZ]]',
          'H:MM[:SS][ tt][ ZZZ][, dddd], mmmm d[w], yyyy',
          -- Internet Standards (relaxed; RFC-822 and RFC-1123)
          '[dddd, ]d[w] mmmm yy[yy][ HH:MM[:SS][ tt][ ZZZ]]',
          '[ddd, ]dd mmm yy[yy] HH:MM:SS zzzz',
          -- The'%c') Format
          '[dddd, ]mmmm dd, H:MM[:SS][ tt] yyyy',
          -- Other common formats
          'd-mmmm-yy[yy][ H:MM[:SS][ tt][ ZZZ]]',
       for _,s in pairs(templates) do
          expand_fmt(s, known_fmts)

    However, this didn’t work, giving me the same error as before. What am I missing?

    -Robert James,
    Interface Analyst,
    GetWellNetwork, Inc.

    The problem is that the date you’re using also matches this:

    -- HL7 Standard

    If you’re not expecting to process dates in that format, you can simply delete that pattern. Otherwise, you’ll need to do a bit of string manipulation to format the date elements in the right order.

    Jeff Drumm ◊ VP and COO ◊ HICG, LLC. ◊

    actually it is more simple:
    local d=’01262011′
    >> D(‘01262011′,’mmddyyyy’)->’2011-01-26 00:00:00′ trace(‘2011-01-26 00:00:00’)

    Thanks Lev! I have another dateparse – date format question.

    I’ve got a customer sending me a time value with digits out to milliseconds:


    It fails to parse properly when I try to use dateparse on it:

    T.EVN[1].DateTime = MsgIn.EVN[2]:T()

    I’m working around it by truncating the value to 14 characters, essentially removing the milliseconds, but I’m looking for something that will permit me to use the entire value. Is there a trick similar to what you posted above that would work?

    -Robert James,
    Interface Analyst,
    GetWellNetwork, Inc.

    Hello Robert, it is same reply; modify the format specifiers you pipe to D() function. Acceptable format modifiers all listed in very same dateparse.lua module .

You must be logged in to reply to this topic.