Getting the date for x number of days in the future or past

rp-7

#1

Sometimes people will ask how it is that we can have Axure RP spit out the date x amount of days in the future or past. Say, for example, you are prototyping a library website and you need to notify the user that the book they just checked out is due in a week. Only you don’t want to say “in a week”. You want it to actually spit out what the date will be seven days from today.

Thankfully, it is pretty easy to do this using the built-in functions in the “Edit Text” dialog you get when you click the “fx” button in the Case Editor.


Using this function you can set the text of a widget to [[Now.addDays(x)]]. I’ve chosen to use [[Now.addDays(LVAR1)]], because I am allowing the user to enter the amount of days in a Text Field widget.


When you want to go back-in-time, you would use [[Now.addDays(-LVAR1)]].

So the good news is now we can time travel safely from behind our desks…So, literally, where we’re going, we don’t need roads!

WARNING: RAPIDLY FLASHING SCREEN!
See It Live!

And check out the attached .rp file

Enjoy!
TimeTravel.rp (60.8 KB)


#2

This is awesome - and just want I need. However, is there a way to format the output at DD/MM/YYYY instead of the entire Date string?


#3

Hi, this has really helped me with something I’m trying to do :slight_smile: Did you ever work out how to change the date format? I need it to just say the day, date and year, eg Thursday 16th April, any ideas would be awesome!


#4

Just want to say with regard to the the .rp file in the original post, “GREAT SCOTT!!! IT WORKS!”


#5

haha yes! Do you have any ideas on how to change the date format??


#6

Not sure off the top of my head. I think the [[Now]] function is formatted in that manner, so when the add days function does its thing it remains in the same format. I’ve had a bit of a play and can’t seem to get it working with any other point of reference function except [[Now]].

Sorry.


#7

I fear you maybe right, however, I’ll find a way to get it to do what I want eventually.
Thanks again :slight_smile:


#8

Looking at it, because of the abbreviations, the information you are looking to reformat into is all available with a fixed length substring of the output text.

So in theory, when the date is generated you write that substring to an output while triggering an external action of some sort. You could then use that action with some logic to set the full day (7 cases) and month (12 cases) to variables and then use those variables and a number of other substrings (Of the output) to create your correctly formatted date.


#9

thanks but what If I need for example to add 7 days to ‘Today’ and I need the date to be shown as “April 30” without all the rest? is it possible?
thanks,
Raz


#10

Hi RazTabou,

You can do this using either the slice or substring method:

[[Now.addDays(7).slice(0, 10)]]

[[Now.addDays(7).substr(0,10)]]

Both will extract part of the string, from the start and ending parameters (in parentheses). That is, [[Now.addDays(7)]] from today (April 25) will give you:

Wed May 02 2018 10:59:03 GMT-0700 (PDT)

To remove all the other stuff after “02”, you want what’s in between the first and 10th character in the above string, hence the need to extract and return only the first 10 characters, e.g.:

Wed May 02

I’ve attached an example file to demonstrate this - hopefully it helps!

Add7Days.rp (49.5 KB)


unlisted #11

closed #12