I need to query MySQL for the current date (from PHP) in YYYY-MM-DD
format... anyone?
$date = date("yyyy-mm-dd", strtotime(now));
The mktime() function is an inbuilt function in PHP which is used to return the Unix timestamp for a date. The timestamp returns a long integer containing the number of seconds between the Unix Epoch (January 1, 1970, 00:00:00 GMT) and the time specified.
Simply put, the Unix timestamp is a way to track time as a running total of seconds. This count starts at the Unix Epoch on January 1st, 1970 at UTC. Therefore, the Unix timestamp is merely the number of seconds between a particular date and the Unix Epoch.
PHP's time() returns a current Unix timestamp. With this, you can use the date() function to format it to your needs. the 2nd argument of the date function is assumed to be time() if left empty.
MySQL curdate
:
You can do in query:
select curdate()
PHP date
echo date('Y-m-d');
If you want to pass your own date format:
echo date('Y-m-d', strtotime($your_date));
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