Have an idea?

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

time stamp for a question

Would using this code above with the hour string also show minutes?  I need to show hours and minutes but not the day.
related to an answer for: Change text based on time of day
asked Jun 28, 2021 by sallen Bronze (2,315 points)

1 Answer

0 votes
 
Best answer
Change %H to %R.

This will display hours and minutes in a 24 hour clock format.

If you want a 12 hour format, change %H to %I %M.
answered Jun 28, 2021 by Paul Moon Platinum (98,770 points)
selected Jun 28, 2021 by sallen
Thanks.  I am using this just to have a time stamp and not show dependent script. How would I adjust this to not show the day?
[%Begin Unverified Perl
   
 my $datestring="";
    
 $datestring=localtime();
   
 SETVALUE("EndTimeStamp",$datestring);
   
End Unverified%]
That script will show the full date string. What you need, which is in the earlier post, is this ...
[%Begin Unverified Perl
 
use POSIX qw(strftime);
 
my $timestring="";
  
$timestring=strftime "%R", localtime;
 
SETVALUE("L1TimeStamp",$timestring);
 
End Unverified%]

This will capture the hour and minutes in a 24 hour clock format.

If you want a 12 hour clock format, try this ...
[%Begin Unverified Perl
 
use POSIX qw(strftime);
 
my $timestring="";
  
$timestring=strftime "%I %M", localtime;
 
SETVALUE("L1TimeStamp",$timestring);
 
End Unverified%]
Thanks.  Do I no longer need to call the time stamp?  I have set that as a pass-in field so it shows up as a variable (which is what I am interested in).
Oops a copy and paste gone wrong.

Change the return line to the SETVALUE line.

return $timestring;

should be ...

SETVALUE("L1TimeStamp"",$timestring);

I have corrected the earlier post.
Thank you!
this does not show the time in the added variable.  I wonder what I might be doing wrong..
OK, let's go through the steps carefully.

1/ Insert this Perl Script in to the footer of your question where you want to perform the time stamp.
[%Begin Unverified Perl
  
 use POSIX qw(strftime);
  
 my $timestring="";
   
 $timestring=strftime "%I:%M", localtime;
  
 SETVALUE("L1TimeStamp",$timestring);
  
End Unverified%]

2/ Go to the pass-in fields and define "L1TimeStamp" as a text variable. This is not a numeric variable.

3/ Test the survey to the page after your time stamp question. You need to submit this page for it to capture the time stamp in "L1TimeStamp". If you want the time captured at the moment it is about to land on the survey page, I would recommend placing the time stamp (the Perl Script) on the page before as this will capture the correct moment.

I just tested this myself and it worked very nicely.
OK.  I will try it again.  I did those three steps above but trying with %R.  Does the size of the indentations matter in the Perl script?
I wouldn't think the indentations would be any issue.

Ensure you define your pass-in variable as a text variable. If you have defined it as numeric, it is likely to be the reason you have no data captured.
I did have some issues with %R? Not sure why? But I can check up on that.

But %I:%M works just nice.
Ok. I can try with the other.
The %I:%M captures a 12 hour clock.

If you need a 24 hour clock, use %H:%M.
Thanks.  This works (%H:%M)!
Hi again, this is working great MOST of the time.  However, some respondents are going back to update some of the information and the time is changing as a result.  Is there a way to restrict this to the time that each question of interest was first viewed/responded to?
One obvious approach is to remove the BACK button and don't allow the respondents to go back.

If you do not want to do that, I would suggest you contact Sawtooth Software direct or post a new question on the forum and see what comes of it.
Thanks.  I didn't know the script could call the first time a page was opened only.  I will post a new question then.
...