Skip to content
Advertisement

SQL Server Time Format is not equal to Client Side Time format

I’m trying to compare the client side time format ("14:00") to SQL Server time format ("14:00:00.0000000") with SQL Query, technically is not equal because SQL Server time format has seconds and milliseconds, so I tried to concatenate the seconds and milliseconds to client side time format in PHP script like this 14:00.":00.0000000" and yet is not equal to SQL Server time format.

My script in PHP:

So how can I compare these two with SQL Query and PHP Script?

Advertisement

Answer

I think that you may consider the following:

  • Do not concatenate strings to build a statement and use parameters in your statements to prevent possible SQL injection issues.
  • Pass date and time values as text using unambiguous date and time formats – yyyymmdd and hh:mm:ss.
  • For your specific case, you may try to compare the date and time values using explicit cast and adding only seconds for the time values.

An example, that is a possible solution to your problem:

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