On this page
- 1 PHP: Date and Time Function
- 2 PHP: Date and Time Function
- 2.1 date() function
- 2.2 How to check for the 1st day of an year in php
- 2.3 How to get time difference in minutes in PHP?
- 2.3.0.1 CRUD App in PHP
- 2.3.0.2 Understanding PHP’s Array Manipulation: Exploring References and Unsetting
- 2.3.0.3 PHP built-in functions
- 2.3.0.4 Mastering Dependency Management with Composer: A Comprehensive Guid
- 2.3.0.5 Associative Array Example in PHP
- 2.3.0.6 Class and Object Example in PHP
- 2.3.0.7 PHP: Sum of two number
- 2.3.0.8 PHP How to get first and last name from full name?
- 2.3.0.9 How to create CSV file in PHP?
- 2.3.0.10 PHP: serialize() Function
- 2.3.0.11 Cheatsheet: PHP
- 2.3.0.12 PHP: global variable
- 2.3.0.13 Understanding PHP Error Reporting Configuration
- 2.3.0.14 PHP : Function
- 2.3.0.15 PHP: JSON Encode and Decode
- 2.3.0.16 PHP: Scrap Images Using cURL
- 2.3.0.17 What is curl in php?
- 2.3.0.18 PHP: Quiz App
- 2.3.0.19 PHP Tutorials
- 2.3.0.20 PHP: Arrays
- 2.4 Leave A Comment Cancel reply
PHP: Date and Time Function
PHP: Date and Time Function
June 8, 2020
Every programming have inbuilt function or Object which handles date and time. PHP also have a date and time function. let’s see how it’s work.
On this page
date() function
The date() function formats a local date and time, and returns the formatted date string. The date function should have at least one parameter.
date(format, timestamp)
PHP microtime function returns current Unix timestamp with microseconds.
microtime(bool $as_float = false): string|float
1 microseconds = 0.001 milliseconds
1000 microseconds = 1 milliseconds
$startTime = microtime(true); //get time in micro seconds usleep(100); $endTime = microtime(true); echo "Milliseconds to execute:". ($endTime-$startTime)*1000;
How to check for the 1st day of an year in php
<?php if ( date('z') === '0' ) { echo "Today is the first day of the year."; } ?>
z – The day of the year (from 0 through 365)
Source: https://stackoverflow.com/questions/12001467/how-to-check-for-the-1st-day-of-an-year-in-php
How to get time difference in minutes in PHP?
<?php $to_time = strtotime("2008-12-13 10:27:00"); $from_time = strtotime("2008-12-13 10:21:00"); echo round(abs($to_time - $from_time) / 60,2). " minute"; ?>