U3F1ZWV6ZTc5OTgzNDMxMzE1MzJfRnJlZTUwNDYwNDY0NzA3Nzc=

The date () function returns previous date

The date () function returns previous date


Question :
I utilized a basic content to refresh the present date at the server side through hag work yet it returns past date. The windows date is right. I attempted to check the content in online php editorial manager and it return past date. don't have the foggiest idea where is the issue.
<?php
$current_date = date("Y/m/d");

$update_d = "UPDATE product SET c_date = '$current_date' ";
$run_d = mysqli_query($con, $update_d);

if ($run_d) {    
    echo "<script>alert('Current Date Updated Successfully!')</script>";
  }
?>


Solution:
The DATE_FORMAT() function formats a date as specified.

Syntax

DATE_FORMAT(dateformat)
The following mysql code
SELECT DATE_FORMAT(CURDATE(),'%Y/%m/%d');
Gives you as result 2020/04/30
So following code would do what you want
<?php

$update_d = "UPDATE product SET c_date = DATE_FORMAT(CURDATE(),'%Y/%m/%d');";
$run_d = mysqli_query($con, $update_d);

if ($run_d) {    
    echo "<script>alert('Current Date Updated Successfully!')</script>";
  }
?>
if you want to improve the solution
comment to help the community


Comments
No comments
Post a Comment

Post a Comment

NameEmailMessage