0

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'

3
Contributors
2
Replies
5
Views
3 Years
Discussion Span
Last Post by broj1
1

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);
0
// 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];

Edited by broj1

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.