Skip to content
Advertisement

Current time from SQL Server to PHP for compare

Need get info, is EndDate expired or not (EndDate is row, where typed info about date of buyed user premium)

JavaScript

result like Jul 14 2020 02:36:00:000PM (if EndDate in smalldatetime data type)

JavaScript

result like 2020-07-15 14:51:21

If i use $time in this row, it update enddate to curent time:

JavaScript

It succesfully compare “lastlogin” and “enddate”, and if account is new or user be online last time before EndDate expired – change EndDate to current time, that succesfully takes from $time. But if user login after EndDate, it not works

Want this compare:

JavaScript

Change to compare like:

JavaScript

Help please How can I take current time from mssql or change $time for something, that can compare? Tried strtotime, but can’t do it (sql server check it in miliseconds, but my php old and can’t use date(“Y-m-d H:i:s:v”) format)

Advertisement

Answer

Note, that the MSSQL PHP extension is not available anymore on Windows with PHP 5.3 and removed in PHP 7.0.0, but if you want a solution, you may try the following:

  • Specify how the datetime values are returned from the SQL Server by setting the mssql.datetimeconvert option in your php.ini file to Off. When this option is On the datetime values are returned converted to SQL server settings. When this option is Off the datetime values are returned in YYYY-MM-DD hh:mm:ss format.
  • Use date_create() to create and compare the dates as PHP datetime objects.

The next simplified example demonstrates this approach (tested with PHP 5.2.9):

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement