RE: [PHP] US Date -> UK Date
| From: | Matthias Endler | Date: | Thu, 19 Oct 2000 05:57:58 +0000 |
| Subject: | RE: [PHP] US Date -> UK Date | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-21097@lists.php.net to get a copy of this message | ||
> On Thu, 19 Oct 2000, James Crowley wrote:
> > Hi,
> > I am using MS SQL, which returns dates in the format
> yyyy-mm-dd. How do I
> > then convert this to another format? (ie date("d m
> y",$datefield) ). If I
> > attempt to convert it at the moment, it doesn't work.
> >
> > Thanks,
> >
> > - James
>
> First up, if you want to send to the list by replying to a non-related
> message, please trim the old message (in this case there were several
> hundred lines of digest stuff!!)
>
> Now, to your question. the date function expects a date in unix timestamp
> format (seconds since 1 Jan 1970) which you aren't using. If you need to
> just display the date without manipulating it once it has been extracted
> from M$ $ql, use explode on the separator to place the d m and y parts in
> an array, then just display the array elements in the desired order, with
> your preferred separator.
>
> Alternatively, you could muck around with mkdate...
Hi,
with M$ $QL you can create your UNIX-timestamp right in your query.
Example:
SELECT DATEDIFF(SECOND,'1970-01-01',datefield) AS datefield FROM table;
Convert to UK-date (mm/dd/yy):
SELECT CONVERT(CHAR(8),datefield,3) AS datefield FROM table;
Convert to UK-date (mm/dd/yyyy):
SELECT CONVERT(CHAR(10),datefield,103) AS datefield FROM table;
Hope this helps.
Cheers,
Matthias