I have one problem... There is a table in my MySQL database that stores to-do list entries inside a JQuery-type calendar.
I had to generate a calendar_id
that will generate a reminder once I created timestamp (considered as time I clicked on any of the calender dateboxes, to key in some to-do tasks - put it simple: created datetime).
This to-do list activities app is an external application that I've been working on to integrate with my own management system. I noticed that,the timestamp column is in int(11)
format, so whatever timestamp entered will be converted into integer.
For example, take a look at this:
2012-02-22 15:31:24
converted to
1329899400
How can we convert datetime to this format? It's not in seconds when I tried:
intval(floor($datetime/86400));
Any help?
In this method, we are using strftime() function of datetime class which converts it into the string which can be converted to an integer using the int() function. Returns : It returns the string representation of the date or time object. Code: Python3.
Example 1: Integer timestamp of the current date and timeConvert the DateTime object into timestamp using DateTime. timestamp() method. We will get the timestamp in seconds. And then round off the timestamp and explicitly typecast the floating-point number into an integer to get the integer timestamp in seconds.
To convert Date to Numeric format in R, use the as. POSIXct() function and then you can coerce it to a numeric value using as. numeric() function.
FROM UNIXTIME
can format UNIX timestamps into datetime fields:
SELECT FROM_UNIXTIME(time)
FROM ...
The reverse function would be UNIX_TIMESTAMP
.
Alternatively you can do it in PHP, if available:
To store a date into the DB format it like this:
$datetimeStr = '2012-02-22 15:31:24';
$datetime = strtotime($datetimeStr);
To retrieve it from the DB and format it to the original format, use something like this:
$dateTimeFromDB = '1329921084';
$datetimeStr = date('Y-m-d H:i:s', $dateTimeFromDB);
Here's a nice MySQL's UNIX_TIMESTAMP()
function for you
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With