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
Solved

Dynamic date for variable

Posted on 2016-09-05
7
40 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 109

Expert Comment

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

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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 55

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 109

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 109

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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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 …

856 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