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
https://forums.phpfreaks.com/topic/64815-solved-numeric-value-to-date-format/
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.

<?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.

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.