How to convert varchar data type to mysql timestamp?

I have a mysql database with a 'tblevel' table with a 'waktu' column with a varchar data type. and the column values ​​are saved as follows:

30-01-2014 12:19:09

The value will be converted to a timestamp, because I have to do this to view the data on the chart, in this case I use Google data visualization,

Shortened code:

$result = mysql_query("SELECT TIMESTAMPDIFF(MINUTE,FROM_UNIX_TIMESTAMP(STR_TO_DATE(waktu, '%H:%i:%s %b %d, %Y')), now()) as waktu1,level,press FROM tblevel WHERE TIMESTAMPDIFF(MINUTE,FROM_UNIXTIME(waktu) , now()) < 120 Order By waktu"); 

hope someone helps fix the .thanks code
relates to Fixduino.

+4
source share
2 answers

Try the following:

SELECT a.waktu, a.level, a.press 
       TIMESTAMPDIFF(MINUTE, STR_TO_DATE(a.waktu, '%d-%m-%Y %H:%i:%s'), NOW()) AS waktu1           
FROM tblevel a
WHERE TIMESTAMPDIFF(MINUTE, STR_TO_DATE(a.waktu, '%d-%m-%Y %H:%i:%s'), NOW()) < 120 
ORDER BY STR_TO_DATE(a.waktu, '%d-%m-%Y %H:%i:%s'); 
0
source

MySQL date format is YMD, try

SELECT a.waktu, a.level, a.press 
       TIMESTAMPDIFF(MINUTE, STR_TO_DATE(a.waktu, '%y-%M-%d %H:%i:%s'), NOW()) AS waktu1           
FROM tblevel a
WHERE TIMESTAMPDIFF(MINUTE, STR_TO_DATE(a.waktu, '%y-%M-%d %H:%i:%s'), NOW()) < 120 
ORDER BY STR_TO_DATE(a.waktu, '%y-%M-%d %H:%i:%s'); 
0
source

Source: https://habr.com/ru/post/1524431/


All Articles