Have an idea?

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

Show in date format

Dear All,

I have convert time to my local time but it show only number and now i want to it show in date format like DD-MMM.

My script :
<script>    
$(document).ready(function(){    
    var lines = `[% ((SystemTime()+25200)/86400)+25569 %]`.split('\n');    
    var text = '';    
    for (var i = 0; i < lines.length; i += 2) {    
        text += lines[i];    
        text += '\n';    
    }    
    $('#Q2').val(text);    
})
</script>


Is it possible?
asked Feb 20 by Saroeun Bronze (1,440 points)

2 Answers

+1 vote
I would do this with JavaScript's Date class:

<script>
$(document).ready(function(){
    var offset = -420;
    
    var now = new Date();
    var localizedNow = new Date(now.getTime() + (offset + now.getTimezoneOffset()) * 60 * 1000);
    var localizedDay = localizedNow.getDate();
    var localizedMonth = localizedNow.getMonth() + 1;
    $('#Q2').val(localizedDay + '-' + localizedMonth);
})
</script>


JS's Date uses the respondent's timezone, so line 3 needs to be updated with the number of minutes off from UTC you are.
answered Feb 20 by Zachary Platinum Sawtooth Software, Inc. (81,800 points)
Thanks Zachary for chiming in. Onya mate.
Thanks, Zachary

In my local time i have change -420 to 420.

<script>
$(document).ready(function(){
    var offset = 420;
     
    var now = new Date();
    var localizedNow = new Date(now.getTime() + (offset + now.getTimezoneOffset()) * 60 * 1000);
    var localizedDay = localizedNow.getDate();
    var localizedMonth = localizedNow.getMonth() + 1;
    $('#Q2').val(localizedDay + '-' + localizedMonth);
})
</script>
0 votes
Try this in Excel ...
=A1/86400+DATE(1970,1,1)

Change "A1" to the applicable Excel cell reference.

Set your date format accordingly also.
answered Feb 20 by Paul Moon Platinum (62,030 points)
You could just use the above formula and apply an offset to convert your time.
=A1+???/86400+DATE(1970,1,1)
Thanks, Paul.

No need in excel, i want to show in screen.
OK, misunderstanding on my part.

I was thinking you were at the analysis stage wanting to convert it there.

I know Sawtooth does not have an SSI Script function handy.

I suggest contacting Zachary Anderson direct at zachary@sawtoothsoftware.com. I'm sure he can assist.

Let me know how you go.
Thanks, Paul.
...