سؤال

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

لا يوجد حل صحيح

نصائح أخرى

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
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top