I would like to convert the May 1, 2017 12:15:00 PM so that it reads like so 1493612100000
Then convert it into string. Is it possible in Java and MySQL and how to do it?
I would like to convert the May 1, 2017 12:15:00 PM so that it reads like so 1493612100000
Then convert it into string. Is it possible in Java and MySQL and how to do it?
You can do this in MySQL in two steps. First, convert the string timestamp to a datetime
using STR_TO_DATE(), then convert that date to milliseconds since the epoch using UNIX_TIMESTAMP().
SELECT 1000*UNIX_TIMESTAMP(STR_TO_DATE(col, '%M %e, %Y %h:%i:%s %p')) AS millis
FROM yourTable
This will return milliseconds since the epoch, which is what your sample data is referring to.
Demo here:
What you mean
1493612100000
? If it is only comparable integer you can use next solution.
Mysql have function UNIX_TIMESTAMP it may be used like this:
SELECT UNIX_TIMESTAMP(`table`.`date`) from `table` WHERE ...;
To convert your string to date use:
STR_TO_DATE('May 1, 2017 12:15:00 PM', '%M %d, %Y %h:%i:%s%p')
Together:
SELECT UNIX_TIMESTAMP( STR_TO_DATE( ... ) )