Have an idea?

Visit Sawtooth Software Feedback to share your ideas on how we can improve our products.

Change text based on time of day

Curious if anyone knows of a way to call upon the specific time of day, say based on the local time of the server?  Specifically, I'm looking into changing some text on the screen after 5pm local time.  Instead of "You will receive it today" I would want to change it after 5pm to "You will receive it tomorrow".  So far I've only seen how to call upon the specific timestamp of a particular moment vs. a 24 hour clock.
asked Apr 14, 2020 by Jay Rutherford Platinum (50,145 points)
Paul, this looks EXACTLY what I'm looking for.  I'll spend a bit more time testing it in a bit, but I did take a look at that tutorial website and there is a lot of good info there.  Thanks as always for you input and a good solution.  I'll let you know how it goes later.
And if you get curious about strftime ...

"strftime" means "string from time". You can format the time in different desirable ways.
Thanks Paul, I was actually, haha.  This worked out perfect for me and I got exactly what I needed plus a few ideas for the future.

1 Answer

0 votes
Hi there Jay, does this help you?

First the full date and time ...
Local date and time: [%Begin Unverified Perl

 my $datestring="";

 return $datestring;

End Unverified%]

OR just the hour ...
Local hour: [%Begin Unverified Perl

use POSIX qw(strftime);

my $hourstring="";
$hourstring=strftime "%H", localtime;

return $hourstring;

End Unverified%]

Just on the second example, use $hourstring to display the appropriate script (e.g. if $hourstring>16 ...).
answered Apr 14, 2020 by Paul Moon Platinum (98,770 points)
edited Apr 14, 2020 by Paul Moon
And check out this useful website ...

Example ...
You will receive it [%Begin Unverified Perl

use POSIX qw(strftime);

my $hourstring="";
$hourstring=strftime "%H", localtime;

if ($hourstring>16)
  return "tomorrow";    
  return "today";    

End Unverified%]
time stamp for a question