Solved

Dynamic date for variable

Posted on 2016-09-05
7
32 Views
Last Modified: 2016-09-06
$directory_with_files = './';

Open in new window


Each day I create a file with todays date, How can I make the variable equal to dynamically be todays date?
0
Comment
Question by:Jasmine Ikhreishi
7 Comments
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 41784760
$d = date('Ymd');
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 41784761
0
 
LVL 1

Author Comment

by:Jasmine Ikhreishi
ID: 41784764
It's not letting me, Can I create a folder with todays date? a php that creates a folder with todays date?
0
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
LVL 51

Accepted Solution

by:
Julian Hansen earned 500 total points
ID: 41784785
Do you mean like this?

<?php
$basedir = './';
$dirname = $basedir . date('Ymd');
if (!is_dir($dirname)) {
   mkdir($dirname);
}

Open in new window

If you want the date separated
<?php
$basedir = './';
$dirname = $basedir . date('Y-m-d');
if (!is_dir($dirname)) {
   mkdir($dirname);
}

Open in new window

0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 41784818
It's not letting me
OK, but what happened, actually?  Did you get a parse error?  Did you get a file permissions error?  If you can give us a little more information -- specific information like error messages and line numbers -- we can probably give you the right help.  Without it, we might guess, but that usually wastes everyone's time.
0
 
LVL 29

Expert Comment

by:Olaf Doschke
ID: 41784819
Are you trying to fromat the date with slashes? Slashes are not allowed characters in folder/directory or file names, as they are the separators of folders/names in the file system, not only on Linux and Mac, also on Windows you are not allowed to use slashes, even though there the separator character is a backslash.

There's a good reason you got the advice to use Ymd, as that is in highest significance to lowest significance of date parts and thus alphabetic sorting also sorts by date in that format AND it does only contain the digits, no unallowed charracter. Whether to use dashes o not may be a matter of taste. You may also combine this, eg as in './orders of '.date('Ymd')

Bye, Olaf.
0
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 41784834
Can I create a folder with todays date?
Yes, but it seems that you might benefit from taking a more structured approach to learning PHP.  There are some helpful resources in this article.
https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html

If the issue is creating the folder (this assumes you know how to create a string variable with today's date), the PHP.net web site has information about how PHP interacts with the file system.  These links may be helpful:
http://php.net/manual/en/book.dir.php
http://php.net/manual/en/book.filesystem.php
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now