Reputation: 568
we want to make a script that renames the file name with a date stamp, we're new to PHP so this is what we have now.
<?php rename("test.txt", "tes3.txt"); ?>
we tried some with things like this below but we don't get it to work.
$date = new DateTime();
echo $date->format('Y-m-d H:i:sP') . "\n";
I hope you guys have a answer how we can do this. Thanks
Upvotes: 2
Views: 4449
Reputation: 476584
All you have to do is use the textual output (string) produced by $date->format(...)
and inject the answer in the rename call.
$date = new DateTime();
rename("test.txt", "test" . $date->format('Y-m-d H:i:sP') . ".txt");
But it is advisable to not use any spaces in filenames, especially if you want the files to be accessible through a server/website/...
Upvotes: 4