-4

So I was trying to display the current Day and date of today using php but instead it displays the last day of the month. I did tried to display the last day of the month before i tried ti display the current date of today and it works.

I tried to re do in another new php page but the result is still the same.

<html>
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
    <?php`enter code here`
    echo date("D - t - m - Y");
    ?>
</body>

I just wanted to display my current date at my place only.

2 Answers2

0

You want something like this.

$timestamp = time();

data('Y-m-d H-i-s', $timestamp);

You can class use DateTime class.

$d = new DateTime('NOW', new DateTimeZone('Europe/London');

echo $d->format('Y-m-d H:i:s);

You can try out different formatting options and choose which best suits your needs.

Edit, adding an echo, and also the timezone option That's all that is needed to echo out the object value, DateTime and DateTimeZone are inbuilt classes of PHP so you should have no issues using them.

Per your comment, I believe that your computers time zone may be incorrect or the php versions default time zone.

CodingInTheUK
  • 930
  • 7
  • 16
  • I dont understand how to use this. Whats weird is that, i could get the correct date and time if i code it on another laptop. But its wrong on mine. Could it be my laptop is having problem? if it does, what is the problem ? T_T and im sorry i couldnt understand your code. – Afiq Hussaini Aug 02 '19 at 02:51
  • Okay, then it seems you have an incorrect timezone on your computer set. Check that out in your computers settings. As for how to use this, see my edit. – CodingInTheUK Aug 03 '19 at 20:40
0
 <?php
    $dt = new DateTime();
    echo $dt->format('Y-m-d H:i:s');
   ?>

    Result:- 2019-08-2 02:26:26