Solved

Datetime string in php

Posted on 2011-03-05
3
1,008 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

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…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

773 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