Format Time from the now() - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

Format Time from the now()

Last post 02-05-2014 08:49 AM by jaxkookie. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 02-04-2014 02:00 PM

    Format Time from the now()

     I have a CommentsHistory field, Every time comments are entered into the Comment field, I concat, timestamp, comments ,commentshistory , timestamp in the now() like this

    concat(substring(now(), 6, 2), "/", substring(now(), 9, 2), "/", substring(now(), 1, 4), "  ", substring(now(), 12, 2), ":", substring(now(), 15, 2), ":", substring(now(), 18, 2)) 

     

    what I want to do is check this  substring(now(), 12, 2) (the Hour) and if value is greater than 12, I want to subtract 12 and set PM

    On change of my comments field I have this condition

    The expression : round(substring(now(), 12, 2)) > 12  but it is giving an error.

     

    Am I missing something?  

     

    Kind regards,
    Larry
    Filed under:
  • 02-04-2014 08:38 PM In reply to

    Re: Format Time from the now()

     Here's how you can adjust the hour number:

    substring(now(), 12, 2) mod 12 + 12 * not(substring(now(), 12, 2) mod 12)

    And here's how you can get the AM/PM part:

    substring("AMPM", 1 + 2 * (substring(now(), 12, 2) >= 12), 2)

    Note that if you have qRules, you can use the FormatDate command to do this much more easily:

    concat("FormatDate /format=G /value=", now())   <-- this is locale dependent, but will produce the M/d/yyyy hh:mm:ss tt format in the US locale.

    concat("FormatDate /format=MM/dd/yyyy hh:mm:ss tt /value=", now())   <-- not locale dependent

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 02-05-2014 05:40 AM In reply to

    Re: Format Time from the now()

     Jimmy,

    you rock, once again!

    So this work in the client, but not in the browser. When I publish I get an unsupported expression, when I open from the library it opens in the client now. If I didn't say this in ver 2007.

    this is my complete formula

    concat(substring(xdDate:Now(), 6, 2), "/", substring(xdDate:Now(), 9, 2), "/", substring(xdDate:Now(), 1, 4), " ", substring(xdDate:Now(), 12, 2) mod 12 + 12 * not(substring(xdDate:Now(), 12, 2) mod 12), ":", substring(xdDate:Now(), 15, 2), " ", substring("AMPM", 1 + 2 * (substring(xdDate:Now(), 12, 2) >= 12), 2))

    the parts you provided are in red and blue. when I remove the red, it works.

    do you have any other magic tricks?

    Kind regards,
    Larry
  • 02-05-2014 07:45 AM In reply to

    Re: Format Time from the now()

    Please try this for the red part. My original version may have been a little too funky:

    substring(now(), 12, 2) mod 12 + 12 * ((substring(now(), 12, 2) mod 12) = 0)

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 02-05-2014 08:49 AM In reply to

    Re: Format Time from the now()

     thanks brother, you rock! works perfectly. I wont pretend to understand it, lol

    Kind regards,
    Larry
Page 1 of 1 (5 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.