I want to write something in my code which will generate a unix timestamp of that precise (up to seconds perhaps or even more precise) time eg.
$today_UNIX = mktime(today);
echo $today_UNIX;
Which would equal something like 22102007122323.
Can't seem to find the system variable for the date.
Many thanks,
How to post UNIX timestamp for today
Moderator: General Moderators
Re: How to post UNIX timestamp for today
If you only need the date you shouldn't be using a timestamp. If you really need the timestamp of midnight today though, you'll need to pass some arguments to mktime(). All the necessary values can be found using date().
Re: How to post UNIX timestamp for today
Well I need something that I can append to a temporary filename, since anyone can do this at any time I want to minimise the chance of two users being on at exactly the same time and creating a file with the same name and causing problems.
Hence just a string of numbers that represent that precise moment in time to make a file like so.. tmp_12122008121212.jpg .
Hence just a string of numbers that represent that precise moment in time to make a file like so.. tmp_12122008121212.jpg .
Re: How to post UNIX timestamp for today
SOLVED: microtime()
Re: How to post UNIX timestamp for today
By "trying to minimise the chance" of something happening you're really saying "I'm hoping this never happens but it might!". The chance needs to be zero. I'd embed the user's id or username into the filename myself, and/or use an incrementing version number. Using a timestamp is too much of a risk.tommy1987 wrote:Well I need something that I can append to a temporary filename, since anyone can do this at any time I want to minimise the chance of two users being on at exactly the same time and creating a file with the same name and causing problems.
Hence just a string of numbers that represent that precise moment in time to make a file like so.. tmp_12122008121212.jpg.
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
Re: How to post UNIX timestamp for today
just name the file it's own MD5 - then who cares about collisions? It would be the same file!
Re: How to post UNIX timestamp for today
You'd have to do an extra check to make sure it's not a shared asset if you delete the file if the user is deleted. That could get messy if it ever went wrong.Kieran Huggins wrote:just name the file it's own MD5 - then who cares about collisions? It would be the same file!