-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);
4

1 回答 1

0

不知道你在追求什么,但 PHP 的日期格式会是这样的

int strtotime ( string $time [, int $now = time() ] )
于 2013-02-12T03:32:33.120 回答