Search code examples
phpdatemkdir

How can I dynamically make folder with today's date?


Is it possible and if it is, how can I create automatically folders that have the names of the current date? I read that mkdir() will make me do the folders but how exactly to set the name of these folders so when I get information from some link the folder where i have to save this .txt file to be created with for example - name: 'May-21-2014' (the current date).


Solution

  • The first input of mkdir() is the name. Just put the string of the date into the value you pass it:

    $name=date("l");
    makdir($name//etc)
    

    would result in a folder called Monday.

    Just format the date as you want it.

    I would suggest folders to be yyyymmdd - eg 20140522 for today, it makes them sort nicely in ascending date order in a normal directory browser.

    This would be:

    $name=date('Ymd');
    

    when you make the folder name.