-1

I want to use the $_GET[] along with the getdate() to pull in the date as query string in the form of: YYYY-mm-dd. If no date is entered, then get the current date. This is what I have done, but I don't have a clue as to if I'm close or not.

if(!isset($_GET['date']))
{
//$date = "2012-09-15"; 
$date = date('Y-m-d');
}
elseif(DateTime::createFromFormat('Y-m-d', $_GET['date']))
{
//$date = DateTime::createFromFormat('Y-m-d',$_GET['date']);
$date = $_GET['date'];
}
else
{
$date = date('Y-m-d');
}
$calendar = DateTime::createFromFormat('Y-m-d', $date);

//This is something else I was attempting

//if(isset($_GET['date']) ? $_GET['date'] : $date = date('Y-m-d')
//$date = explode("-", $_GET['date']);
//$date = date('Y-m-d');
// Create new DateTime object passing the date as a string.
$calendar = DateTime::createFromFormat('Y-m-d', $date);
  • 1
    What exactly is the problem? – John V. Feb 12 '13 at 03:26
  • The above code works for me. If you are looking for improvements to it you can always pull the format out into a variable so that you can manage that in one spot. $format = 'Y-m-d'; $date = date($format); – Levi Feb 12 '13 at 03:34
  • Please clarify your question. What are you trying to accomplish? – Ben D Feb 12 '13 at 04:34

1 Answers1

0

not to sure what you are after but the date format for PHP would be something like this

int strtotime ( string $time [, int $now = time() ] )
Tomazi
  • 781
  • 9
  • 27
  • 46
  • @Alex The problem is that when I select a new day on the calendar, it is not changing to new day, is there something like a reset or clear I have to do for that to happen? I have a variable $day_of_month which is suppose to be current day selected that shows up highlighted, but that is not the case right now. Thanks for the tip Levi. – user2046996 Feb 12 '13 at 13:16