Getting a date from MS SQL in the correct format.
| From: | Richard Quadling | Date: | Mon, 02 Apr 2001 16:09:32 +0000 |
| Subject: | Getting a date from MS SQL in the correct format. | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-8145@lists.php.net to get a copy of this message | ||
I want to extract a date from a datetime field in Microsoft SQL, via ODBC
('cause we support different databases, or so I'm told, and hey, what do I
know!!!!! <grrrrr!>).
I want the format to be CCYYMMDD.
Is there a MS SQL function for this?
I've found DATEPART("YYYY",field), but I don't know how to get all the bits
(i.e. YYYY, MM, DD). I get a numerical addition.
If I CAST as varchar, I don't get a 0 for <10 on MM and DD.
i.e. 1st January 2001 comes out as 200111 rather than 20010101
I know there must be a format function, but SQL novice here can't find it.
Any suggestions. In the mean time, I've had to use DATEPART to pull the
three bits in separately and add a bit to the PHP templates to add them all
together. Ideally I want just the value as CCYYMMDD.
Regards,
Richard Quadling.