DEV Community

loading...

MYSQL Query With Timestamp Long Values

Mukit, Ataul
I consider myself as an enthusiast in learning new things everyday, about our history and future as well as the present. My interests: Ancient History, Comparative Religion, Science and Tech, C++
・1 min read


function MySQLTimeStampCompatibleString(timestamp){
    return new Date(timestamp).toISOString().substring(0, 19).replace('T', ' ');
}
   
function queryWithTimestampLongValues(fromTime, toTime) {

    var query = "";    

    if(fromTime && toTime){      

        query += 'SELECT * FROM user_info WHERE 
                   user_info.created_at > TIMESTAMP("' +     
                   MySQLTimeStampCompatibleString(fromTime) + '") AND 
                   user_info.created_at < TIMESTAMP("' + 
                   MySQLTimeStampCompatibleString(toTime) +  '")';
    

    }

    return query;
}   

Discussion (0)