Solved

Datetime string in php

Posted on 2011-03-05
3
994 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses four methods for overlaying images in a container on a web page
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 …

760 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now