Jump to content

strtotime not working


Recommended Posts

Hi,

 

im trying to convert my data in a table to a date using the strtotime function, the code is...

<?php $approvaldate = strtotime(date($row_rsworksorders1['intraartapproval'], strtotime($date)) . "+15 days"); echo $approvaldate; ?>

 

only its outputting as 2132130149 as opposed to a date, can anybody shed some light on whats going wrong?

Link to comment
https://forums.phpfreaks.com/topic/201674-strtotime-not-working/
Share on other sites

You're using the functions incorrectly.

strtotime converts a readable date into the number of seconds since 1970-01-01

date formats the number of seconds since 1970-01-01 into a readable date.

 

What values are in the variables $row_rsworksorders1['intraartapproval'] and $date?

 

Ken

Ahhh thanks for clarifying that ken,

Ive found another way about it which is working but updating the month and not the day!

 

<?php $today = $row_rsworksorders1['intraartapproval'];
			$est = strtotime('+15 day', strtotime($today));
			print date('d/m/Y', $est); ?>

 

Have you any idea why?

My 'Date of approval' field is varchar, I have tried using the DATE type but no matter what I was trying I couldnt get it to input correctly so Ive settled with VARCHAR as this way at least it shows. So the strtotime, what is causing it to only update the month?

If the format is dd/mm/yyyy, that's the reason that str to time is having a problem. It expects the date to be in mm/dd/yyyy format when you use slashes. This is why having the MySQL column of type DATE is important, since it forces the date to be YYYY-MM-DD.

 

To use this input do something like:

<?php
list ($d,$m,$y) = explode('/',$row_rsworksorders1['intraartapproval']);
$today = "$y-$m-$d";
$est = strtotime('+15 day', strtotime($today));
echo $est;
?>

 

Ken

 

Like I said before, strtotime converts the date into the number of seconds since 1970-01-01. To get a formated date you have to use the date function:

<?php
list ($d,$m,$y) = explode('/',$row_rsworksorders1['intraartapproval']);
$today = "$y-$m-$d";
$est = date('Y-m-d',strtotime('+15 day', strtotime($today)));
echo $est;
?>

 

Ken

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.