Jump to content

[SOLVED] numeric value to date format


iiker

Recommended Posts

I have a number, let's say 140820071211 (todays date and time at 12 11) and now i need to conver it to date format (ie 14. Aug 2007 12 11) How would i do that? is there any function that makes it to date (ei i give the date format i first used date('jmYGi'); and it returns the date ?)

Link to comment
Share on other sites

well now i understand, but theres still a problem.

my number isn't a timestamp. its just a date and time pushed together and now i need to separate it again.

using functions in w3schools's page gives wrong result. function date(format, timestamp) requires timestamp that i don't have.

Link to comment
Share on other sites

<?php
$timestamp = 140820071211;
$unix_timestamp = mktime(substr($timestamp,8,2), substr($timestamp,10,2), 0, substr($timestamp,2,2), substr($timestamp,0,2), substr($timestamp,4,4));
echo date('r', $unix_timestamp);
?>

 

date() only takes UNIX timestamps.

Link to comment
Share on other sites

apparantly that number is not a timestamp dan...

 

so the only solution is to take the string and spilt it up just and a position - so take first 2 digits as day, next 2 as month etc....

 

this requires that the data is a string and that leading zeros are maintained so that the 'number' is always a uniform length

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.