Home > database >  getting date like 'Wed, 1 Dec 2021 16:05:39' in php
getting date like 'Wed, 1 Dec 2021 16:05:39' in php

Time:12-01

CODE

<?php
$date = date("D, d M Y H:i:s ", strtotime(' 5 hour   30 minutes '));
echo $date;
?>

OUTPUT

Wed, 01 Dec 2021 16:05:39

NEEDED OUTPUT

Wed, 1 Dec 2021 16:05:39

DESCRIPTION

By using the above php code I have been getting the output with the date 01 but I need to get the date like 1 like in the needed output.

CodePudding user response:

As per https://www.php.net/manual/en/datetime.format.php, you can use the token j to show the day of the month without leading zeroes.

$date = date("D, j M Y H:i:s ", strtotime(' 5 hour   30 minutes '));
echo $date;

Live demo: http://sandbox.onlinephpfunctions.com/code/7ffb1967f04670be78a0718b0874733b0ea96554

  • Related