> 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...


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to