Skip to content

AS3 – AIR – SQLite – Dates


Warning: Use of undefined constant gad_content_tag_filter_replace - assumed 'gad_content_tag_filter_replace' (this will throw an Error in a future version of PHP) in /home/surfer_u/labs.andrewu.net/wp-content/plugins/web-ninja-google-analytics/webninja_ga.php on line 1813
var sql:String;
sql = "CREATE TABLE IF NOT EXISTS customers (";
sql += "createtime VARCHAR(255)";
sql += ");";

var sqlInsert:String;
sqlInsert = "INSERT into customers(create time) values (";
var dateNow:Date = new Date();
sqlInsert = "'"+toSqlDate(dateNow)+"'";
sqlInsert += ");";

public function lpad(original:Object, length:int, pad:String):String {
     var padded:String = original == null ? "" : original.toString();
     while (padded.length < length) padded = pad + padded;
     return padded;
}

public function toSqlDate(dateVal:Date):String {
    return dateVal == null ? null : dateVal.fullYear
       + "-" + lpad(dateVal.month + 1,2,'0')  // month is zero-based
       + "-" + lpad(dateVal.date,2,'0')
       + " " + lpad(dateVal.hours,2,'0')
       + ":" + lpad(dateVal.minutes,2,'0')
       + ":" + lpad(dateVal.seconds,2,'0')
       + ":" + lpad(dateVal.milliseconds,3,'0')
       + " ET";
}

source

Post a Comment

Your email is never published nor shared. Required fields are marked *
*
*