note 62229 added to function.mssql-query

From: Date: Wed, 22 Feb 2006 22:37:30 +0000
Subject: note 62229 added to function.mssql-query
Groups: php.notes 
Request: Send a blank email to php-notes+get-104250@lists.php.net to get a copy of this message
Just explaining how to get date in YYYY-MM-DD format much easily, when you use convert function in SQL you usually give the format as one of the arguments. for example <br> select convert(varchar(20),getdate(),20)<br> select convert(varchar(20),getdate(),120)<br> will both return dates in yyyy-mm-dd hh:mi:ss(24h) format. you can also use <br> select convert(varchar(20),getdate(),21)<br> select convert(varchar(20),getdate(),121)<br> in yyyy-mm-dd hh:mi:ss.mmm(24h) formats.<br> So now when you have the date as string from either of the four convert functions you can either take the left part of the string or use a substring function to get the date in YYYY-MM-DD format.<br> following are few examples.<br> select left(convert(varchar(20),getdate(),20),10)<br> select left(convert(varchar(20),getdate(),120),10)<br> select left(convert(varchar(20),getdate(),21),10)<br> select left(convert(varchar(20),getdate(),121),10)<br> select substring(convert(varchar(20),getdate(),20),1,10)<br> select substring(convert(varchar(20),getdate(),20),1,10)<br> select substring(convert(varchar(20),getdate(),120),1,10)<br> select substring(convert(varchar(20),getdate(),21),1,10)<br> select substring(convert(varchar(20),getdate(),121),1,10)<br> ---- Server IP: 64.71.164.2 Probable Submitter: 205.238.135.10 ---- Manual Page -- http://www.php.net/manual/en/function.mssql-query.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+62229 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+62229&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+62229&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+62229&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+62229&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+62229&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+62229&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+62229&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+62229&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#104250) next »