Storing SQL Server 2005 datetime
I have a php script inserting values in to SQL Server 2005 table via SQL
$date = '15 Jun 2011 00:00';
$sql = "INSERT INTO shows ( DateStart ) VALUES ( '$date')";
I have 2 issues:
1) how best to convert this date into something SQL Server understands? The default format is mm/dd/yyyy on my system but I want to present the dates 开发者_如何学Cas readable to the user.
2) When inserting an empty string the DateStart value gets set to 1/1/1900. How best to convert an "invalid" date into a NULL (the column already accepts NULLs) so that if $date = ""
then DateStart IS NULL
Thanks!
- Point 1: Use ISO date format
YYYY-MM-DDTHH:MM:SS
Note: For date only useYYYYMMDD
becuase of anomalies in how SQL Server parse dates - Point 2:
NULLIF(value, '')
I think the datetime format while inserting the record in datetime column should always "YYYY-MM-DD HH:MM:SS" Default Format
gbn already told.
精彩评论