The best place to *find* answers to programming/development questions, imo, however it's the *worst* place to *ask* questions (if your first question/comment doesn't get any up-rating/response, then u can't ask anymore questions--ridiculously unrealistic), but again, a great reference for *finding* answers.

My Music (Nickleus)


how to create a date timestamp in javascript and a sahi script

here's normal javascript code for creating a date timestamp, using double digits for month, day, hour, minute and second, even when the value is between 0-9:

var now = new Date();
var y = now.getFullYear();
var m = now.getMonth()+1; // month is zero based, i.e. january is 0
var d = now.getDate();
var h = now.getHours();
var min = now.getMinutes();
var s = now.getSeconds();


// OUTPUT format YYYYMMDDHHMMSS, e.g. 20130104090106 (i.e. 2013-01-04 09:01:06)

to do it in sahi, just add the variable sign (dollar sign) in front of the variable names and use " instead of ':

var $now = new Date();
var $y = $now.getFullYear();
var $m = $now.getMonth()+1;
var $d = $now.getDate();
var $h = $now.getHours();
var $min = $now.getMinutes();
var $s = $now.getSeconds();


function foo() {
  _setValue(_textbox(67), "DESPATCH_AUTOTEST_" + $y+($m<=9?"0"+$m:$m)+($d<=9?"0"+$d:$d)+($h<=9?"0"+$h:$h)+($min<=9?"0"+$min:$min)+($s<=9?"0"+$s:$s));

No comments:

Post a Comment