Solved

Datetime string in php

Posted on 2011-03-05
3
1,010 Views
Last Modified: 2012-05-11
I am not familiar with PHP but i need some script that produces a datetime string that I can use as a filename in Linux.

The datetime string should be the current date and time.  It should also include milliseconds if possible.
0
Comment
Question by:soozh
3 Comments
 
LVL 4

Accepted Solution

by:
mars-vie earned 167 total points
ID: 35043205
Hello!

Would this be what you are looking for -->

echo date("Ymdhis");

Detailed description of this function
http://www.php.net/manual/en/function.date.php

Also possible: microseconds (added in PHP 5.2.2)
echo date('Ymdhisu');
0
 
LVL 20

Assisted Solution

by:Mark Brady
Mark Brady earned 166 total points
ID: 35043210
You could do something like this:

$fname = "yourDefaultFilename_here"; // if you wanted something as well as the date for filename
$date = time();
$fname = $date."_".$fname;

Now the $fname variable has the date at the beginning of it. There are many MANY ways to format the date so if you want miliseconds as well then you would do something like this:

$date = date(DATE_RFC822);

Just google "php datetime" and you will have many results
0
 
LVL 27

Assisted Solution

by:Lukasz Chmielewski
Lukasz Chmielewski earned 167 total points
ID: 35043605
The best to do would be to get unix timestamp for filename - which you can easily convert to time and will provide a unique filename,
<?php
$filename = time().".txt";
?>
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

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 is …
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…
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…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

832 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