Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Datetime string in php

Posted on 2011-03-05
3
Medium Priority
?
1,024 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

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!

Question has a verified solution.

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

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
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 look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

604 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