liamloveslearning Posted May 13, 2010 Share Posted May 13, 2010 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? Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted May 13, 2010 Share Posted May 13, 2010 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 Quote Link to comment Share on other sites More sharing options...
liamloveslearning Posted May 13, 2010 Author Share Posted May 13, 2010 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? Quote Link to comment Share on other sites More sharing options...
liamloveslearning Posted May 13, 2010 Author Share Posted May 13, 2010 Tried allsorts! has anybody got any alternative ideas? Quote Link to comment Share on other sites More sharing options...
liamloveslearning Posted May 13, 2010 Author Share Posted May 13, 2010 Im just wondering, I have my data type as VARCHAR, could this be conflicting with the date() function? Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted May 13, 2010 Share Posted May 13, 2010 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 Quote Link to comment Share on other sites More sharing options...
liamloveslearning Posted May 13, 2010 Author Share Posted May 13, 2010 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? Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted May 13, 2010 Share Posted May 13, 2010 What is the value of $row_rsworksorders1['intraartapproval']? Ken Quote Link to comment Share on other sites More sharing options...
liamloveslearning Posted May 13, 2010 Author Share Posted May 13, 2010 it varies, its user inputted so its something along the lines of 12/05/2010 Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted May 13, 2010 Share Posted May 13, 2010 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 Quote Link to comment Share on other sites More sharing options...
liamloveslearning Posted May 13, 2010 Author Share Posted May 13, 2010 Thanks for explaining that Ken, Its not outputting in a string of numbers however, my 'art approval date' is 02/05/2010 and the estimated date which should add 15 days is showing as 1274068800 Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted May 13, 2010 Share Posted May 13, 2010 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 Quote Link to comment Share on other sites More sharing options...
liamloveslearning Posted May 13, 2010 Author Share Posted May 13, 2010 Sorry, getting late and very frustrated, for some unknown reason its now going back in time and outputting 31/12/1969 Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted May 13, 2010 Share Posted May 13, 2010 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 Quote Link to comment Share on other sites More sharing options...
liamloveslearning Posted May 14, 2010 Author Share Posted May 14, 2010 When I echo the data its being output correctly as dd/mm/yyyy, however it is a varchar so I think this could be the problem? Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted May 14, 2010 Share Posted May 14, 2010 The date format "dd/mm/yyyy" is not correct for strtotime, it needs to be "mm/dd/yyyy" if you're using slashes. Ken Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.