?
Solved

Datetime string in php

Posted on 2011-03-05
3
Medium Priority
?
1,020 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
[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
3 Comments
 
LVL 4

Accepted Solution

by:
mars-vie earned 668 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 664 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 668 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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article discusses how to implement server side field validation and display customized error messages to the client.
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 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…
Suggested Courses

762 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