Search code examples
phpdatemkdir

PHP mkdir - Why is this an invalid argument?


I wanted to experiment with creating directories titled with the date and current time. I know I can use the php time() function, but that is hard for me to read. Why can't I create a directory named 06-11-2014 11:37:04 or so? The php mkdir function is giving me an invalid argument when I try to use this format.

php code

<?php
$newdate = date("m-d-Y H:i:s");

mkdir($newdate, 0755, true);

?>

Solution

  • The colons in the date are messing it up. Your best bet is to use a format like this:

    $newdate = date("m-d-Y H_i_s");