Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help..

Status
Not open for further replies.

krappleby

Programmer
Jul 25, 2006
25
GB
Hi all,

im not a proffessional programmer (or speller for that matter) but i do do quite a lot of programming for friends and family, one of the main things i always have problem with is times and dates..

here is my problem.

i have a date/time field in a mysql database, which i need to pull..

i do so and have the result say

1976/06/23 00:00:00

now.. i need to add 1 month to that date.. i have tried allsorts, to do this, but fail every time..

in my last attempt, i took todays date, added one month and ended up with a date about 33 years ago.

can someone please explain as to how i do this. i have checked the php manual but it only tells you how to allocate 1 month to the date() function, and not to a pulled mysql db record..

for arguments sake,. lets say the variable that holds the date is

$newdate

any help would be appreciated..
tahnks
 
thanks for the info. i have read the page to do with this.. but still not doing it right..

here is the mysql code

update DOWNLINES set MEMBER_ID = '" . $new_np . "', NP_REG_DATE = '" . $newdate . "', MAINT_DATE = DATE_ADD('" . $new_np_date2 . "', INTERVAL 1 MONTH), where UNIQUECODE = '" . $memid . "'

any ideas

thanks for the help
 
i havent cut anything off the middle of the code. lol.
from your statement there is a load missing.. ok..

i am not very experianced with mysql statements..
and the $new_np_date2 variable is

2009/12/30
 
in the case above.. the variable is just passed, via a form..

 
all i am trying to do is i have a form, where someone enters a date, say 30/12/2009

the form is processed and the date is formatted to

2009/12/30 as per the timedate in a database
i then process that to add 00:00:00

now.. the field $new_np_date2 contains only 2009/12/30

i need to add 1 month to that date.

simple
 
Hi

spamjim said:
but I like to use unix timestamps in databases where I need to do a lot of calculations based on time.
That is the best choice when you have nothing suitable for date/time handling. SQL database servers usually have a special data type, the [tt]interval[/tt], and a lot of functions and operators to perform calculations. Letting the SQL server to calculate has the benefit of handling timezone and daylight saving differences too.


Feherke.
 
@OP

Code:
echo date('Y-m-j h:i:s', strtotime('+1 month', strtotime('2009/12/30')));

or something like that. (for a php solution as opposed to mysql).
 
Not sure why you'd be trying to accomplish this with mySQL... couldn't you just grab the time from the server serving up the sign up page?
Keeping in mind that by default the month January will actually equal 0 instead of 1.

I recently built something in ActionScript that captured local machine time and had to reformat the date / time to make it decipherable when generating reports.
i.e 1/0/2010 now reads 01/01/2010 in this structure day/month/year.

I have some code examples but again they are in ActionScript not php so I won't post it here.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top