Hi i have input type text as date with a value of "2013-12-25"
and i have a database with a field of month and a value of (December) and Year (2013).

How can i convert the value of (2013-12-25) to a string of December and Year so i can use it to my

Select Persons from Customer where Month = '$Month' and Year = '$Year'

Recommended Answers

All 2 Replies

Member Avatar for diafol

I would advise against storing your dates like this. The format: "2013-12-25" should suffice for your DB too. I can't imagine a scenario where storing a date in two fields is better than one - even if the first 'day' part is not being used.

Otherwise:

$month = date('F', strtotime($dateFromPicker));
$year = substr($dateFromPicker,0,4);
// set the array with month names
$monthNames = array('January', 'February', ...);

// this is your date in a form of a string
$dateString = '2013-12-25';
// change it to an array
$dateArray = explode('-', $dateString);
// month is the second element (-1 to get the correct index)
$Month = $monthNames[$dateArray[1] - 1];
// the year is the first element 
$Year = $dateArray[0];
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.