DEV Community

loading...

MYSQL Query With Timestamp Long Values

lucpattyn profile image Mukit, Ataul ・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)

pic
Editor guide