I want to be able to run a script via the command line and pass it a date for a function.
How would I go about doing this? I.e I need to pass it to a function within the file and pass it a typed date in the format. YYYY-MM-DD HH-MM Where the second MM is minutes not Month.
Would I need to use particular flags in the command or is there a simpler way?
Why don't you use:
$date = date("Y-m-d H:i:s");
in your script?
Edit:
If you want to catch a parameter, you should use $argv
array:
if (!isset($argv[1])) {
die("You should give a date as first parameter
");
}
if (!@strtotime($argv[1])) {
die("The date you given is invalid.
");
}
$date = $argv[1];