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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

Which column has that datatype? That shouldn't matter since strtotime wants a string as it's input, but if that's the datatype of your date field in the database it really should have a type of DATE or DATETIME.

 

Ken

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

The strtotime function will do that when it doesn't understand the date it's been given.

 

Echo out all the input values that you're using.

 

I just tested my code and it gave me the correct answer.

 

Ken

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.