close ad
Databridge V2 with MySQLi support IS Now Available!
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Need som help with php date calculations from mysql database

Thread began 3/01/2012 12:33 pm by Rune Brynestad | Last modified 3/02/2012 1:30 pm by Rune Brynestad | 800 views | 6 replies |

Rune Brynestad

Need som help with php date calculations from mysql database

I'm trying to find out how to calculate dates. This is what I have found out:

Todays date is: <?php echo date("d.m.Y H:i:s"); ?>

Todays date + 2 weeks is: <?php echo date ('d.m.Y H:i:s', strtotime("+2 week")); ?>

Arrival date displayed from a database is <?php echo date ('d.m.Y H:i:s', strtotime($row_rsArrivals['arrivaldate'])); ?>

But what is Arrival date displayed from a database + 2 weeks ?

Regards
Rune

Sign in to reply to this post

Jason ByrnesWebAssist

that would be:

php:
<?php echo date ('d.m.Y H:i:s'strtotime($row_rsArrivals['arrivaldate']."+ 2 week")); ?>
Sign in to reply to this post

Rune Brynestad

Thanks. Your suggestion works perfect.

I have another case. If the arrival date is more than 2 weeks old, the user should be redirected to another page, so I believe I have to use an if statement like this:

<?php if (date("d.m.Y H:i:s") > (date('d.m.Y H:i:s', strtotime($row_rsArrivals['arrivaldate']."+ 2 week")))) { ?>
<?php
header ( 'Location: redigering_stengt.php' ) ;
?>
<?php } ?>

But the user is not redirected, no syntax error in my if statement.

I'm attaching a file where I have put together an example. You can also see it on live URL here:

Untitled-2.php

Thanks

Regards
Rune

Attached Files
Untitled-2.zip
Sign in to reply to this post

Jason ByrnesWebAssist

you have the if statement at line 1.

the recordset is not created till line 41.

you wont be able to use the data in the recordset in your if statement till the recordset is created by the code.

the if statement needs to be moved so it is after the recordset.

Sign in to reply to this post

Rune Brynestad

Yes, that make sense, but it's still not working.

I have moved the if statement below the recordset, I'm uploading a new version of the file. Live URL is also updated,

Untitled-2.php

Please have another look. Thanks in advice.

Regards
Rune

Attached Files
Untitled-2.zip
Sign in to reply to this post

Jason ByrnesWebAssist

your dates are strings.

the less than operator is a mathematical operation.

you cannot perform math on a string data type, only on a number data type.

try using this for your if statement instead

php:
<?php if (time() > strtotime($row_rsMottattdato['mottatt_dato']."+ 2 week")) { ?>
Sign in to reply to this post

Rune Brynestad

As far as I can see, it works perfect.

Thanks again for helping me on this.

Regards
Rune

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...