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? Link to comment https://forums.phpfreaks.com/topic/201674-strtotime-not-working/ 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 Link to comment https://forums.phpfreaks.com/topic/201674-strtotime-not-working/#findComment-1057941 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? Link to comment https://forums.phpfreaks.com/topic/201674-strtotime-not-working/#findComment-1057945 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? Link to comment https://forums.phpfreaks.com/topic/201674-strtotime-not-working/#findComment-1057984 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? Link to comment https://forums.phpfreaks.com/topic/201674-strtotime-not-working/#findComment-1057986 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 Link to comment https://forums.phpfreaks.com/topic/201674-strtotime-not-working/#findComment-1057991 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? Link to comment https://forums.phpfreaks.com/topic/201674-strtotime-not-working/#findComment-1057995 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 Link to comment https://forums.phpfreaks.com/topic/201674-strtotime-not-working/#findComment-1057997 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 Link to comment https://forums.phpfreaks.com/topic/201674-strtotime-not-working/#findComment-1058002 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 Link to comment https://forums.phpfreaks.com/topic/201674-strtotime-not-working/#findComment-1058004 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 Link to comment https://forums.phpfreaks.com/topic/201674-strtotime-not-working/#findComment-1058006 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 Link to comment https://forums.phpfreaks.com/topic/201674-strtotime-not-working/#findComment-1058009 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 Link to comment https://forums.phpfreaks.com/topic/201674-strtotime-not-working/#findComment-1058015 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 Link to comment https://forums.phpfreaks.com/topic/201674-strtotime-not-working/#findComment-1058022 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? Link to comment https://forums.phpfreaks.com/topic/201674-strtotime-not-working/#findComment-1058123 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 Link to comment https://forums.phpfreaks.com/topic/201674-strtotime-not-working/#findComment-1058511 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.