?
Solved

Dynamic date for variable

Posted on 2016-09-05
7
Medium Priority
?
47 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 111

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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 58

Accepted Solution

by:
Julian Hansen earned 2000 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 111

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 111

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

Video: Liquid Web Managed WordPress Comparisons

If you run run a WordPress, you understand the potential headaches you may face when updating your plugins and themes. Do you choose to update on the fly and risk taking down your site; or do you set up a staging, keep it in sync with your live site and use that to test updates?

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

765 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