Jump to content

Convert date to time stamp


Dragosvr92

Recommended Posts

Hello, i need a fast convertor that converts the date format 03-03-2008, 08:26 PM into a timestamp fast.

Like, you paste 03-03-2008, 08:26 PM into a post form, submit and it gives you the time stamp.

 

I made a convertor a whille ago, but you need to insert each numbers into a separate input box (day, months, year etc)

I cant remember how exactly it functions etc asi haventtouched PHP In a while.....

 

 

Link to comment
https://forums.phpfreaks.com/topic/254367-convert-date-to-time-stamp/
Share on other sites

  Quote

strtotime() won't work well on this particular format because it's ambiguous.  You should use explode() to pull the date apart and then use mktime()

Thank you, i will look at that tomorrow. I didnt thought on using explode()

I remembered why i had to use a input for each area and didnt made it like this

Thanks Dan, but that doesnt look like what i need.

 

I Made the script myself, but i have a problem on detecting if its either morning or night, using mktime().

For example there may be 03-05-2008, 02:17 AM, and 03-05-2008, 02:17 PM.

 

A solution i thought about would be to make some if statement and check if PM is selected, and if it is, check an array and if it finds, for example: " 03 " it replaces it with " 15 ".

 

here is some lame script i made.....

 

 

$chars[5] outputs PM/AM

$chars[3] outputs the hour

 

<?//AM
if ($chars[5]=='AM' || $chars[3])

{
array{
"01" = "13";
"02" = "14";
"03" = "15";
"04" = "16";
"05" = "17";
"06" = "18";
"07" = "19";
"08" = "20";
"09" = "21";
"10" = "22";
"11" = "23";
"12" = "00";
}
}
?>

 

Can you please give me a example?

With c it outputs 2008-03-03T20:26:00+00:00

With A it outputs PM/AM

 

This is my Code:

<?
if (isset($_POST['DATE']))
{
$str = $_POST['DATE'];
$chars = preg_split('/[-:, ]+/', $str);

$timestamp = mktime($chars[3], $chars[4], '00', $chars[0], $chars[1], $chars[2]);

echo date('m-d-Y, h:i A', $timestamp);
echo '<br />', '<br />';
echo $timestamp;
}
?>

 

I just need to make an array and replace for example 08 with 20, so that the time may be set as PM.

I think you are getting confused :-\

  • 1 month later...

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.