now() function question - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

now() function question

Last post 05-31-2019 12:33 PM by Travis_H. 20 replies.
Page 1 of 2 (21 items) 1 2 Next >
Sort Posts: Previous Next
  • 09-30-2011 03:57 PM

    now() function question

     When I have a now( ) function enabled, it seems to display like this:

     2011-09-30T11:40:37

     What's the "T" for in the middle and how can I get rid of it?

     Probably a simple question, but I'm just learning this stuff...just started using InfoPath 2010 day before yesterday.

    Thanks!
    Dan

  • 09-30-2011 04:09 PM In reply to

    Re: now() function question

     I kind of answered my own question - I opted to display both the date and the time in separate fields.  But if anyone still has any insight, I would still love to hear from you.

     Thanks again.
    Dan

  • 09-30-2011 04:13 PM In reply to

    Re: now() function question

    The "T" stands for Time, of course (but you knew that) - this is just the date format used by InfoPath - no matter how you display your date / time, if you look at the XML in a text editor, you'll see the data structure is in this format. You can change the way the data is displayed in your form by formatting your control (for example, text box or expression box control) under the control's properties - you can choose how to display the date and time.

    Here's some fun reading if you'd like more info on the XML spec for Date Time (the term "fun" is being used extremely flippantly here).

    Hilary Stoupa

  • 09-30-2011 06:50 PM In reply to

    Re: now() function question

    If you want to change the format of the date you can do so with some other functions.

    concat

    substring

    number

    Here is a formula I used to show the date in the format I was looking for -- 9/30/2011.

    concat(number(substring(now(), 6, 2)), "/", number(substring(now(), 9, 2)), "/", number(substring(now(), 1, 4)))

    Broken down

    concat - will display any number of fields or text together separated by a comma ','

    So to get Month/Day/Year you need to start with the field or function to give you the date/time, then the slash is enclosed in quotes "/".

    substring - pulls the values out of the function result. now() return the time in this format YYYYMMDDTHHMMSS so the substring function takes three parameters, the first is field, the second is the start location to extract, and the third is the number of character to extract.

    So to get the Month, start with the Field or Function to return the date/time, 6 is the first character to start from, and 2 is the number of characters to extract.

    number - wraps the substring function to return a number from a string.

    So to get the Day out of the date/time is to start with 9th character and then return 2 characters. Lastly the year, start with the first character and return the first 4 characters. I hope this helps.

    If you want to include the time separately use the same process to add to the concat function

    I've also used this formula to develop unique ID's based on the return result of the now() function.

    Scott
  • 02-22-2012 04:33 PM In reply to

    Re: now() function question

    Thank you Scott, I'll take your instructions into consideration!  :)

  • 11-18-2014 01:38 PM In reply to

    Re: now() function question

    Nice to find a reply that actually works...Thanks Scott.

    This works to pull HHMM from now(): substring-after(now(), "T")

    To use this code within the form, add Now to myfields and use substring-after(now(), "T") as the default value. You can then use field Now to set rules on other date fields.

    PeteyPete

  • 05-22-2015 01:44 AM In reply to

    Re: now() function question

    Sorry to drag up a very old thread - but Scott's post was very helpful. However I can't seem to get it work for the time. I though this would work: concat(number(substring(now(), 10, 4))) Which would show the hour and the minutes (but not seconds) but it doesn't. Anyone can help?? Thanks :)
  • 05-26-2015 08:02 AM In reply to

    Re: now() function question

    substring(now(), 12, 5) 

    Hilary Stoupa

  • 05-28-2015 05:21 AM In reply to

    Re: now() function question

    Thanks Hilary but it still doesn't work?

    This is the formula I have:

    concat(number(substring(now(), 9, 2)), "/", number(substring(now(), 6, 2)), "/", number(substring(now(), 3, 2)), "/", number(substring(now(), 12, 5)), "-", Username)

    It comes up like:

    28_5_15_NaN-username

    So I still can't get the time to work?

  • 06-01-2015 12:52 PM In reply to

    Re: now() function question

    I'm confused as to what you are trying to do and what your desired result is - can you tell me what you want the outcome to look like (your formula has "/" in it, and there are none in your output, so I'm sort of baffled) and attach a sample form under the options tab?

    Thanks! 

    Hilary Stoupa

  • 06-02-2015 12:13 PM In reply to

    Re: now() function question

    Hilary Stoupa:

    I'm confused as to what you are trying to do and what your desired result is - can you tell me what you want the outcome to look like (your formula has "/" in it, and there are none in your output, so I'm sort of baffled) and attach a sample form under the options tab?

    Thanks! 

    Hi Hilary

    Thanks for taking the time to try and help!

    I'm using Scott's formula on the 4th post - so the "/" is there from that. However as you can see from my output - it comes up with underscores instead, although that's not my main problem...

    My desired result is to get the time (not the seconds though) added to the filename as well as the month and date (with username after). Using Scott's formula I successfully got the date and month working. However I couldn't get the time to work. I tried the numbers you suggested - but that didn't work either. This is my formula:

    concat(number(substring(now(), 9, 2)), "/", number(substring(now(), 6, 2)), "/", number(substring(now(), 3, 2)), "/", number(substring(now(), 12, 5)), "-", Username)

    But the 12 and 5 don't seem to work - it results in the NaN. So I get 28_5_15_NaN-username but I want something like 28_5_15_08_10-username (in an ideal world I'd have 28/5/15-08:10-username)

    Can you or anyone help get the time working? Thanks :)

  • 06-02-2015 12:25 PM In reply to

    Re: now() function question

     NaN = Not a Number. You are using number(substring(now(), 12, 5). The time has a ":" in it - thus is not a number. Try substring(now(),12,5) instead.

    If you want underscores instead:

    concat(number(substring(now(), 9, 2)), "_", number(substring(now(), 6, 2)), "_", number(substring(now(), 3, 2)), "_", substring(now(), 12, 5), "-", userName()) 

    Hilary Stoupa

  • 06-02-2015 12:43 PM In reply to

    Re: now() function question

    Hilary Stoupa:

     NaN = Not a Number. You are using number(substring(now(), 12, 5). The time has a ":" in it - thus is not a number. Try substring(now(),12,5) instead.

    If you want underscores instead:

    concat(number(substring(now(), 9, 2)), "_", number(substring(now(), 6, 2)), "_", number(substring(now(), 3, 2)), "_", substring(now(), 12, 5), "-", userName()) 

    Hi Hilary

    Fantastic thanks - I'm at home now but can't wait to test this tomorrow at work!

    Just to note though - even though my formula has slashes in it "/" it actually comes up with underscores instead! I don't want underscores, I want slashes.... any idea why the slashes don't work? (and it automatically subs them for underscores?)

  • 06-02-2015 12:52 PM In reply to

    Re: now() function question

     I'd guess you have something else setting the field? Maybe check it out in the rule inspector.

    Hilary Stoupa

  • 06-03-2015 06:14 AM In reply to

    Re: now() function question

    Hilary Stoupa:

     I'd guess you have something else setting the field? Maybe check it out in the rule inspector.

    Hi Hilary,

    Thanks so much Hilary - got it all working! Very helpful advice on here - thanks :)

Page 1 of 2 (21 items) 1 2 Next >
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.