Solved

Dynamic date for variable

Posted on 2016-09-05
7
43 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 110

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
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!

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
This article discusses four methods for overlaying images in a container on a web page
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

732 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