| Often you will be required to store a date in | | | | that will by run by your database server. |
| MySQL. Either upon an update of an existing | | | | Below you will find a quick method to generate |
| record, or on a fresh insert of a new record. | | | | the date value for the two types of MySQL field |
| Good programmers are particular about the type | | | | types: date, and datetime. |
| and quality of data that is stored in a MySQL | | | | Step 1. Create a field in your database that is |
| database. Sometime you do not want the date to | | | | either date or datetime. |
| be created by MySQL at the time of the insert | | | | - If the field is of type date, it will have this |
| or update. Rather, you want the date to be | | | | format: [Year-Month-Day]. |
| created in PHP during code execution. Although | | | | - If the field is of type datetime, it will have this |
| the time difference from the date creation could | | | | format: [Year-Month-Day Hour:Minute:Second] |
| be well under a few milliseconds, there is a | | | | Step 2. After you have created the SQL to be |
| difference. This difference could add up if several | | | | used in the MySQL Query, populate the date field |
| transactional sequences must happen. | | | | with either the variable $now or $today. Doing so, |
| A simple alternative is to create the date in PHP | | | | will match the insert or update date/time field in |
| and then transfer that information to the query | | | | PHP, to that used in your MySQL database. |