473,386 Members | 2,114 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

problem with time script

In my script main_date = 2007-01-24
and I'm getting this as my result for the due date 2007 04 06
what am I doing wrong here?

Aaron

<?
$maint_date = date(' Y m d', $maint_date);
if ($maint_interv = "monthly")
{
$interval = //mktime(0, 0, 0, date("m")+ 1, 1, date("Y"));
"1 week";
}
$interval = strtotime($interval);
$due_date = $maint_date + $interval;
echo date(' Y m d', $due_date);
echo "<br>$interval";
?>
Mar 7 '07 #1
6 1084
mds
_Skare_Krow_ wrote:
$due_date = $maint_date + $interval;
this adds int to string.
Mar 7 '07 #2
mds wrote:
_Skare_Krow_ wrote:
>$due_date = $maint_date + $interval;

this adds int to string.
ok so how do I add something to a date?

Mar 7 '07 #3
_Skare_Krow_ wrote:
In my script main_date = 2007-01-24
and I'm getting this as my result for the due date 2007 04 06
what am I doing wrong here?

Aaron

<?
$maint_date = date(' Y m d', $maint_date);
if ($maint_interv = "monthly")
{
$interval = //mktime(0, 0, 0, date("m")+ 1, 1, date("Y"));
"1 week";
}
$interval = strtotime($interval);
$due_date = $maint_date + $interval;
echo date(' Y m d', $due_date);
echo "<br>$interval";
?>
do not put this line on:
$maint_date = date(' Y m d', $maint_date);
instead if $maint_date is a string "2007-01-24", do this:
$maint_date = strtotime($maint_date);

remove the reference to interval.
How to calculate interval:
"monthly": interval is 60 sec * 60 minutes * 24 hours * 30 days
so that is: $interval = 60 * 60 * 24 * 30;
assuming 1 month is 30 days of course.

So $due_date is simply $maint_date + $interval
Mar 7 '07 #4
_Skare_Krow_ wrote:
$interval = strtotime("1 week");
This doesn't do what you think it does. strtotime() doesn't output
intervals; it outputs timestamps; here is it returning the timestamp for
the date one week from today.

You need to calculate the interval by yourself:

$interval = 7 * 24 * 60 * 60; // seconds in one week

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux

* = I'm getting there!
Mar 7 '07 #5
"_Skare_Krow_" <pe*******@gmail.comwrote in message
news:lY******************************@sysmatrix.ne t...
mds wrote:
>_Skare_Krow_ wrote:
>>$due_date = $maint_date + $interval;

this adds int to string.

ok so how do I add something to a date?
$original_date = '2007-03-07';
echo date('Y-m-d', strtotime('+1week', strtotime($original_date)));

OR

$original_date = '2007-03-07';
list($Y,$m,$d) = explode('-',$original_date);
echo date('Y-m-d', mktime(12,0,0,$m,$d+7,$Y));

--
"Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpk
http://outolempi.net/ahdistus/ - Satunnaisesti päivittyvä nettisarjis
sp**@outolempi.net | rot13(xv***@bhgbyrzcv.arg)
Mar 7 '07 #6
Hendri Kurniawan wrote:
_Skare_Krow_ wrote:
>In my script main_date = 2007-01-24
and I'm getting this as my result for the due date 2007 04 06
what am I doing wrong here?

Aaron

<?
$maint_date = date(' Y m d', $maint_date);
if ($maint_interv = "monthly")
{
$interval = //mktime(0, 0, 0, date("m")+ 1, 1, date("Y"));
"1 week";
}
$interval = strtotime($interval);
$due_date = $maint_date + $interval;
echo date(' Y m d', $due_date);
echo "<br>$interval";
?>

do not put this line on:
$maint_date = date(' Y m d', $maint_date);
instead if $maint_date is a string "2007-01-24", do this:
$maint_date = strtotime($maint_date);

remove the reference to interval.
How to calculate interval:
"monthly": interval is 60 sec * 60 minutes * 24 hours * 30 days
so that is: $interval = 60 * 60 * 24 * 30;
assuming 1 month is 30 days of course.

So $due_date is simply $maint_date + $interval
Many thanks I can now nest the "intervals" and go on... strtotime just
isn't working quite the way I thought it would.

Aaron
Mar 7 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Bartosz Wegrzyn | last post by:
I need help with sessions. I createt set of web site for nav with authorization. first I go into main.php which looks like this: <?php //common functions include_once '../login/common.php';...
53
by: Andrew Poulos | last post by:
I've got some CSS that looks like this: body { margin: 0; font-family: Arial, Helvetica, sans-serif; font-size: 140.01%; color: #000000; } but IE won't apply the font size to text in table...
8
by: rdlebreton | last post by:
Hi, Folks! I've been trying to develop my own version of these draggable layers and I have been limiting myself to IE6...for now. I have looked at some other examples to get ideas of creating...
2
by: Charles Mendell | last post by:
1. When I go to http://www.w3schools.com/js/default.asp and choose: 2. JS HTML DOM and then choose: 3. the Window object and then choose: 4. Write some text in the windows status bar ( a link)...
13
by: nobody | last post by:
Hello all, I've searched just about everything and although I can see that other people are having problems, but theirs don't seem to relate, so in a last ditch attempt, my posting! Script...
0
by: Leslie McGann | last post by:
Hi, I need to open a different pdf file in an iframe each time the user clicks a button. I also need to open the pdf to a specific page each time. The pdfs in question are located on a web...
6
by: Shamin | last post by:
Hi, Thanks in advance for answering to my Question. I'm stuck with this problem and would really appreciate any help. I have 2 aspx files (Main.aspx and ReportViewer.aspx). Main.aspx has a...
34
by: Simon Wigzell | last post by:
document...focus() will scroll the form to move the specified text field into view on everything I have tried it with except Safari on the MAC. The form doesn't move. Any work around? Thanks.
9
by: Jerim79 | last post by:
Here it is: <?php if($_SERVER=='POST'){ $Number=$_POST; $Email=$_POST; $Number2=0; $error=0;
2
by: swethak | last post by:
Hi, I am getting the problem the problem with google map in Internet Explorer. This map worked fine in mozilla . When i opened the same map in Internet Explorer i am getting the error...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.