Question

Okay so in my data base i have the following columns: id, title, admission, date_start, date_end, time_start, time_end, location, description, image, hyperlink

I am retrieving date_start and date_end from the data base and I have cleaned up the data some, but have not been able to remove the 0 before the dates.

My code so far: http://pastebin.com/eAUXtkaX

The output of the date_start and date_end function is:

Date Start: December 04 - 6 // This is for when two different days are entered into the db
Date Start: December 25 //This is for when two days entered are displayed as the same.

Okay so on the one that is for when two different days are entered into the database, how would i remove the 0 before the first digit?

MySQL Query(Also in the pastebin):

SELECT *, CONCAT(DATE_FORMAT(date_start, '%M %d'),
(IF(date_start = date_end,'',CONCAT(' - ', DAY(date_end))))) newDate 
FROM events3 
WHERE date_end >= CURDATE() 
ORDER BY date_start LIMIT 5
Was it helpful?

Solution

You could use the ltrim() function?

Assuming that the date that you want to strip the 0 of is $date ..

$date = ltrim($date, '0');

Read about it here

If I'm not mistaken, you should replace

$date_start = $rows['date_start'];
$date_end = $rows['date_end'];

With

$date_start = ltrim($rows['date_start'], '0');
$date_end = ltrim($rows['date_end'], '0');
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top