•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 456,588 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,612 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 2359 | Replies: 8
![]() |
I have looked everywhere, I've figured out how to add x amount of days to the current date, or take away x amount of days from the current date. But let's say I have a date stored in my database as "0000-00-00", that is not the current date. How can I take that date and add a certain number of days to it?
I'm using php with a mysql database. I did find one sql command that works when I run it in the sql command line, but not on php. It's
Of course in the command line I put an actual date in the $mydate portion. But in php, it looks like this:
$mydate is just a date in the form 0000-00-00 pulled from somewhere else in my database. But it keeps spitting out "Resource id #8."
What's a simple way to add some days to a given date?
I'm using php with a mysql database. I did find one sql command that works when I run it in the sql command line, but not on php. It's
SELECT DATE_ADD('$mydate', INTERVAL 14 DAY)Of course in the command line I put an actual date in the $mydate portion. But in php, it looks like this:
$next_date=mysql_query("SELECT DATE_ADD('$mydate', INTERVAL 14 DAY)");$mydate is just a date in the form 0000-00-00 pulled from somewhere else in my database. But it keeps spitting out "Resource id #8."
What's a simple way to add some days to a given date?
remember the code that i gave to increase numbers by one... change to datediff and it will work 
$AddOneDay = " mycolumn BETWEEN date_format(Now() + INTERVAL 1 DAY,'%e/%c/%Y - %H:%i:%s') AND date_format(Now(),'%e/%c/%Y - %H:%i:%s') ";
how many days you want, change that 1 to any number...

$AddOneDay = " mycolumn BETWEEN date_format(Now() + INTERVAL 1 DAY,'%e/%c/%Y - %H:%i:%s') AND date_format(Now(),'%e/%c/%Y - %H:%i:%s') ";
how many days you want, change that 1 to any number...
Last edited by fatihpiristine : Nov 2nd, 2007 at 1:00 pm.
Do a favour, leave me alone
•
•
Join Date: Aug 2007
Location: Cavite,Philippines
Posts: 508
Reputation:
Rep Power: 3
Solved Threads: 68
•
•
•
•
I have looked everywhere, I've figured out how to add x amount of days to the current date, or take away x amount of days from the current date. But let's say I have a date stored in my database as "0000-00-00", that is not the current date. How can I take that date and add a certain number of days to it?
I'm using php with a mysql database. I did find one sql command that works when I run it in the sql command line, but not on php. It'sSELECT DATE_ADD('$mydate', INTERVAL 14 DAY)
Of course in the command line I put an actual date in the $mydate portion. But in php, it looks like this:$next_date=mysql_query("SELECT DATE_ADD('$mydate', INTERVAL 14 DAY)");
$mydate is just a date in the form 0000-00-00 pulled from somewhere else in my database. But it keeps spitting out "Resource id #8."
What's a simple way to add some days to a given date?
you must use mysql_result to get the date.
php Syntax (Toggle Plain Text)
$query="SELECT DATE_ADD('$mydate', INTERVAL 14 DAY)"; $result=mysql_query($query) $next_date=mysql_result($result,0,"*date field on your table");
"death is the cure of all diseases..."
http://ryantetek.wordpress.com
http://ryantetek.wordpress.com
•
•
Join Date: Nov 2007
Posts: 3
Reputation:
Rep Power: 0
Solved Threads: 1
php Syntax (Toggle Plain Text)
<?php $num_days = 20; echo date("M-d-Y", mktime(0, 0, 0, m, d, yyyy)+$num_days*60*60*24); ?>
The above is a purely php way of finding the number of days from a certain date. In the date, notice I put m and d and NOT mm and dd. For mktime use 8, not 08 or you will get the wrong date. This is my first post on daniweb, hope everything views OK.
![]() |
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- array structs, size swap functions, the amount of days between to dates (C++)
- Date (Java)
- Function Question! (Computer Science and Software Design)
- help calculating days (C++)
- Countdown to a date (Visual Basic 4 / 5 / 6)
- Logic to Convert Days From 1800 to a Date (Month, Day, Year) (C++)
- How to erase Date Last Accessed Info (Windows NT / 2000 / XP / 2003)
Other Threads in the PHP Forum
- Previous Thread: problem comparing strings
- Next Thread: How to hide .php extension



Linear Mode