How To Convert Date Into Timestamp Using PHP?

03-Apr-2023

.

Admin

How To Convert Date Into Timestamp Using PHP?

Hi Dev,

This example is how to convert date into timestamp using php?.

The task can be done by using the strtotime() function in PHP.

It is used to convert English textual date-time description to a UNIX timestamp.

The UNIX timestamp represents the number of seconds between a particular date and the Unix Epoch.

So let's start following example.

Syntax:


strtotime ($EnglishDateTime, $time_now)

Example:

// PHP program to convert the date

// to timestamp

<?php

//Y-M-D formate :-

$date = "2020-09-23";

$timestamp1 = strtotime($date);

echo $timestamp1;

echo "<br>";

//D-M-Y formate

$date2 = "24-09-2020";

$timestamp2 = strtotime($date2);

echo $timestamp2;

echo "<br>";

//British English words Formate

$date3 = "16 May 2019";

$timestamp3 = strtotime($date3);

echo $timestamp3;

?>

Output:

1600819200

1600905600

1557964800

#PHP 8

#PHP