Solved

Dynamic date for variable

Posted on 2016-09-05
7
45 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 110

Expert Comment

by:Ray Paseur
ID: 41784760
$d = date('Ymd');
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 57

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 110

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 110

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to count occurrences of each item in an array.
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 …

696 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