It is very important to have time and date in website and applications, so here we would describe the method to display the time and date in PHP Programming language.
Date Without Time
echo date("d"); // result: If today is 2019-01-28 so result would be 28.
We can describe it into words;
echo date("D"); // result: Suppose today is Thursday so result would be Thu.
- First Date of Current Month
- Last Date of Current Month
Date with Time
echo date("Y-m-d h:i:sa");
- 2nd Example is One of Complete Format of Date and Time
echo date("l jS \of F Y h:i:s A");
Before displaying date in PHP programming language, need to define time zone as under;
It is compulsory to define time zone prior to display date.
Time zone name can be printed.
Same value is stored in variable and displayed or inserted into database. Later it can be retrieved as per requirement. If there is need to select data between two dates, the following query is used;
select * from table_name where date_column between $start_date and $end_date
If within ‘where’ clause, there are more queries than one, so describe in this way;
select * from table_name where (date_column between $start_date and $end_date) and column_other = 'value_required'
(Note: The above ‘between’ condition is not only for date range but for range of any kind of data (in number).