I am pulling date from local server:
$year = date("Y");
$day = date("d");
$month = date("m");
In my MySQL database, I have three fields, dateday datemonth and dateyear on a record.
Format of database values are 26,6,1971.
I want to select only records with dates that are equal to today or not past yet.
Second question, can I trick date() to give dates in eastern US time when the server is in the UK?
Thanks!!
2
Answers
You don’t "trick
date()
", you use an API that is more useful.Output:
Ref: https://www.php.net/manual/en/class.datetime.php
On a broader note you can simplify your life by storing and computing all dates in a single timezone, ideally UTC as it has no DST or other nonsense attached. Timezones then become solely the the domain of the presentation layer.
To search for table rows that are equal to or greater than today, you can use the following query:
This is what it would look like if you concatenate PHP variables into a PHP string to create the query.
For your second question, you can set the timezone in your PHP script with this command.
Also, you can see more information about timezone here
List of Supported Timezones
date_default_timezone_set information
Final script