Question

I am storing the date in MySQL in the format yyyy-mm-dd. I wish to extract individual elements of the date i.e. day,month and year as separate elements

How should I go about this? I am using php

No correct solution

OTHER TIPS

You can do it using explode function in php. explode('-', $date_obj);

You could make use of the DateTime class which has the createFromFormat.

Like this..

<?php
$date = DateTime::createFromFormat('Y-m-d', '2009-02-23');
echo $date->format('Y');//2009
echo $date->format('F');//February or use 'M' for Feb
echo $date->format('d');//23
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top