RE: [PHP] Date Concat?
| From: | John Holmes | Date: | Fri, 20 Sep 2002 13:15:07 +0000 |
| Subject: | RE: [PHP] Date Concat? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-117011@lists.php.net to get a copy of this message | ||
> I have two fields of type date in a MySQL table called training:
>
> start_date
> end_date
>
> I can format the date using a select, for example
>
> SELECT
> DATE_FORMAT(start_date, '%M %d, %Y') as start_date,
> DATE_FORMAT(end_date, '%M %d, %Y') as end_date
> FROM training
>
> This produces the following:
>
> start_date: September 16, 2002
> end_date: Sepetember 20, 2001
>
> Based on the above, I would like to echo out something like this:
>
> You will be in training September 16 - 20, 2002.
SELECT
CONCAT(
'You will be training ',
DATE_FORMAT(start_date,'%M %d'),
' - ',
IF(MONTH(start_date)!=MONTH(end_date),
DATE_FORMAT(end_date,'%M %d'),
DATE_FORMAT(end_date,'%d')),
' ',
YEAR(end_date))
FROM training
Another option would be to just select out the individual month, day,
and year out of the database, instead of a formatted date. Or select out
a unix_timestamp and use date() to extract the individual parts and
create your string...
---John Holmes...