0
    $date = getdate();
    $query = "UPDATE Members Set Name = '$desiredName', Latest_Update = '$date'  Where ID = '$currentID'";
    if(sqlsrv_query($conn, $query)) {
    echo "Record successfully updated.";
    }

I have this query to update a name of a member and whenever I update the name I want to also update the time of the update. Currently this query does not work with the Latest_Update query but everything else works if I remove that. My question is how do I update a datetimeoffset using this query? As at the moment, it does not send the query.

  • possible duplicate of [`SQL Server equivalent of MySQL's NOW()?`](http://stackoverflow.com/questions/385042/sql-server-equivalent-of-mysqls-now) - `$query = "UPDATE Members Set Name = '$desiredName', Latest_Update = SYSDATETIMEOFFSET() Where ID = '$currentID'";`? [`SYSDATETIMEOFFSET()`](https://msdn.microsoft.com/en-us/library/bb677334.aspx) – Sean May 02 '15 at 16:01
  • http://stackoverflow.com/questions/23740480/sqlsrv-update-statement-runs-but-doesnt-update-db Try the above link Possible you can find your answer. – Asif Mushtaq May 02 '15 at 16:04
  • @Sean Put that as an answer, it worked. Thanks buddy. – river-wild May 02 '15 at 16:08

1 Answers1

0

Rather than create the datetime in php, use the built in function SYSDATETIMEOFFSET()

$query = "UPDATE Members Set Name = '$desiredName', Latest_Update = SYSDATETIMEOFFSET() Where ID = '$currentID'";
Sean
  • 12,443
  • 3
  • 29
  • 47