Go Back   Web Hosting UK Forums | Linux Windows Dedicated Server and cPanel VPS Hosting Forum > Support > php issues.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-25-2007, 10:15 AM
Senior Member
 
Join Date: Jan 2007
Posts: 939
Default PHP date()

I am really struggling with this code below. Anyone help?
I don't understand why it isn't working! I can usually sort any php issues but the code below throws a wobbly.

The code explained:
I have a date that i want to insert into mysql but i want to add days to it beforehand. First I need to convert it into US date (y-m.d) as opposed to (d-m-y) then add the extra days

PHP Code:
//$input1 is the european date carried over from the form
list ($day$month$year) = split ("-"$input1);
$remdate $year."-".$month."-".$day;
$added=strtotime($remdate); 
//$adv is the extra days to add
$outdat=$added + (60*60*24*$adv);
$outdate=date('Y-m-d'$outdat); 
$outdate is giving me the timestamp not the mysql date format.
$outdat and $remdate echo out correctly so the form info is being passed to the script

Can't understand why it isn't though!
__________________
West Dorset Community

Last edited by jon123; 07-25-2007 at 10:18 AM.
Reply With Quote
  #2 (permalink)  
Old 07-25-2007, 11:00 AM
Senior Member
 
Join Date: Jan 2007
Posts: 939
Default

umm, that's strange! it now works.
I received an email saying my login script wasn't working either but now ok.
Server glitch?
Anyway doesn't matter as it now works as it should.
__________________
West Dorset Community
Reply With Quote
  #3 (permalink)  
Old 07-25-2007, 12:53 PM
kev woodman's Avatar
Premium Member
 
Join Date: Jul 2006
Location: Newport, Wales, UK.
Posts: 1,494
Default

Glad it's sorted mate

Couldn't you have used:

PHP Code:
$outdate date("Ymd",strtotime($adv,$added); 
to replace the last two lines?
__________________
homo sum: humani nil a me alienum puto ... ( just Google it )
Reply With Quote
  #4 (permalink)  
Old 07-25-2007, 01:58 PM
Senior Member
 
Join Date: Jan 2007
Posts: 939
Default

Hi Kev,
No because yours uses todays date, mine uses various. Plus adding $adv any other way that converting to seconds first just won't work. It seems to not move the month 'up' when days exceed total for month.

It is probably me but yes you are right, it certainly could be condensed for 'cleaner coding'. This bit is beyond me i'm afraid.
__________________
West Dorset Community
Reply With Quote
  #5 (permalink)  
Old 07-25-2007, 02:29 PM
kev woodman's Avatar
Premium Member
 
Join Date: Jul 2006
Location: Newport, Wales, UK.
Posts: 1,494
Default

I'm unlikely to ever get accused of producing clean code In fact one of my big jobs in the autumn is likely to be refactoring a load of old code before it chokes an entire server.
__________________
homo sum: humani nil a me alienum puto ... ( just Google it )
Reply With Quote
  #6 (permalink)  
Old 07-25-2007, 02:36 PM
Senior Member
 
Join Date: Jan 2007
Posts: 939
Default

Quote:
Originally Posted by kev woodman View Post
I'm unlikely to ever get accused of producing clean code In fact one of my big jobs in the autumn is likely to be refactoring a load of old code before it chokes an entire server.
...lol

my 'Hello World' script could do that.
__________________
West Dorset Community
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 03:56 AM.
Copyright 2002-2007 WebHosting.uk.com. All rights reserved.
Web Hosting UK Forum