I need to create a database which will hold some datetime values.
So I defined the column to be datetime type, and I have this calendar.
So, which should be the format of the calendar input in order for the date time to work?
Because I need to make some searches i.e
Select FROM table_name between date1 to date2
For the moment it is:
mm/dd/yyyy
I’m using this:
$today = date("dd/mm/yyyy");
$strSQL = "SELECT forma.*, SMS_MONTIME.IDTICKET, SMS_MONTIME.MBYLLUR,SMS_MONTIME.time_added
FROM forma
LEFT JOIN SMS_MONTIME ON forma.ID = SMS_MONTIME.IDTICKET WHERE data_e_shitjes=$today";
Thanks
There are many formats supported by SQL Server – see the MSDN Books Online on CAST and CONVERT. Most of those formats are dependant on what settings you have – therefore, these settings might work some times – and sometimes not.
The way to solve this is to use the (slightly adapted) ISO-8601 date format that is supported by SQL Server – this format works always – regardless of your SQL Server language and dateformat settings.
The ISO-8601 format is supported by SQL Server comes in two flavors:
YYYYMMDDfor just dates (no time portion); note here: no dashes!, that’s very important!YYYY-MM-DDis NOT independent of the dateformat settings in your SQL Server and will NOT work in all situations!or:
YYYY-MM-DDTHH:MM:SSfor dates and times – note here: this format has dashes (but they can be omitted), and a fixedTas delimiter between the date and time portion of yourDATETIME.This is valid for SQL Server 2000 and newer.
If you use SQL Server 2008 or newer and the
DATEdatatype (onlyDATE– notDATETIME!), then you can indeed also use theYYYY-MM-DDformat and that will work, too, with any settings in your SQL Server.Don’t ask me why this whole topic is so tricky and somewhat confusing – that’s just the way it is. But with the
YYYYMMDDformat, you should be fine for any version of SQL Server and for any language and dateformat setting in your SQL Server.