close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Need to add 8 hours to a DATETIME

Thread began 4/01/2013 9:28 am by mrs | Last modified 4/02/2013 8:07 am by Christopher West | 4556 views | 8 replies |

mrs

Need to add 8 hours to a DATETIME

Hi, I am running data bridge to create pages where a user inserts content, but I want to limit their ability to update the record once posted. I want to limit their ability to update the record to within 8 hours of it originally being posted. After eight hours, I am going to wrap the update with a WA show region behaviour to hide it.

What I am struggling with is how to add the eight hours to the record, or how I make the show if behaviour hide the update button after eight hours.

Is there a way?

Sign in to reply to this post

Christopher WestCommunity Expert

<?php if(WA_Auth_RulePasses("PaidMember")){ // Begin Show Region ?>
CODE HERE
<?php } // End Show Region ?>

I set up a rules for PaidMember which compared the session MemberValidTo:

<?php echo $_SESSION['MemberValidTo']; ?>
>
to this code: <?php echo date('Y-m-d H:i:s'); ?>

So what you could do is something simular and just ad 8 hours to the current time:


Also could something like this work: for adding 8 hours

strtotime('+8 hours', strtotime(<?php echo date('Y-m-d H:i:s'); ?>));

Chris

Sign in to reply to this post

mrs

I have been trying to get this to work based on the data bridge insert behaviour, and I have this working to post the current date and time:

.$_POST['fld_vLOCKDATE'] = date('Y-m-d H:i:s').

But, as soon as I try to amend it to add in the 8 hours extra, I end up with 0000-00-00 00:00:00 for my date and time.

This is what I have so far which isn't working:

.$_POST['fld_vLOCKDATE'] = date('Y-m-d H:i:s') + ('INTERVAL 8 HOURS').

or

.$_POST['fld_vLOCKDATE'] = date('Y-m-d H:i:s, INTERVAL 8 HOURS').

or

.$_POST['fld_vLOCKDATE'] = date('Y-m-d H:i:s' + '+8 HOURS').

and so on... many iterations of it now that I can't remember them all!

The following is what was produced as code straight from the Dat Assist extension:

.((isset($_POST["fld_vLOCKDATE"]) && $_POST["fld_vLOCKDATE"]!="" )?date("Y-m-d H:i:s", strtotime($_POST["fld_vLOCKDATE"])):"") .

And I've added the code you suggested to the hidden field in my form, but still no joy. Any thoughts on what I can do further?

Thanks so far anyway.

Sign in to reply to this post

Christopher WestCommunity Expert

Another way of adding 8 hours you could use:

$date = date('h:i:s A', time()+28800);

(28800 = seconds) Which = 8 hours
(60 x 60 x 8)

Your probably getting 0000-00-00 00:00:00 as your calculation is adding to the whole datetime so it would end up becoming an invalid calculation. I never done this before, So would need to write the code myself when I am probably at computer.

Chris

Sign in to reply to this post

Christopher WestCommunity Expert

perhaps something like:

<?php echo date('Y-m-d H:i:s' , time()+28800); ?>

could be implimented

Chris

Sign in to reply to this post

Christopher WestCommunity Expert

ok I just done experimenting as I never done this before. how about this code...
as a test copy thid directly:


<?php
$new_time = date(strtotime($_POST['fld_vLOCKDATE'])+60*60*8);
?>
<BR>
<?php echo date('l jS M Y H:i:s' ,$new_time); ?>

I tested the above code using a datime stored in a members table in my own database..this is the code I used:

<?php
$new_time = date(strtotime($row_rsMembers['MemberValidTo'])+60*60*8);
?>
<BR>
<?php echo date('l jS M Y H:i:s' ,$new_time); ?>

currently stored in the members table under MemberValidTo is 2013-04-02 00:00:00
the output of the above code I used gives me: Tuesday 2nd Apr 2013 08:00:00
(Which is +8 hours on the date stored in my database :)

So the above can be altered for your post variable.

Chris

Sign in to reply to this post

Christopher WestCommunity Expert

Ok I think I have something that uses a stored datetime in a users table in the database (if thats what you would want to do since if they update content you would want to store the datetime of that content entry in the users table). (28800 is in seconds = 8 hours)

Ive used long variable names to make the below example more meaningful:
Plus I am echoing the 2 variables just for demonstration of both datetimes to compare.

Its the first time I done this sort of thing so its a little crude :)

<?php
$currentdatetime = date('l jS M Y H:i:s');
$storeddatetimeandeighthours = date('l jS M Y H:i:s',strtotime($row_rsMembers['MemberValidTo'])+28800);
?>
<?php echo $currentdatetime; ?>
<BR>
<?php echo $storeddatetimeandeighthours; ?>
<p>&nbsp;</p>


<?php
if ("".$currentdatetime ."" < "".$storeddatetimeandeighthours ."") { // WebAssist Show If
?>
<p>This text will only show if under the datetime stored in database is less than 8 hours of current datetime</p>
<?php
} // ("".$currentdatetime ."" < "".$storeddatetimeandeighthours ."")
?>

Sign in to reply to this post

Christopher WestCommunity Expert

I think I was adding too much work in my previous post so here is a more simple version :)

<?php
if ("".date('l jS M Y H:i:s') ."" < "".date('l jS M Y H:i:s',strtotime($row_rsMembers['MemberValidTo'])+28800) ."") { // WebAssist Show If
?>
<p>This text will only show if under the datetime stored in database is less than 8 hours of current datetime</p>
<?php
} // ("".$currentdatetime ."" < "".$storeddatetimeandeighthours ."")
?>



(above is to demonstrate only so you would need to replace with your $_POST variables :)

Chris

Sign in to reply to this post

Christopher WestCommunity Expert

Some more funky datetime manipulation:

As this is my first time experimenting with this I would like to share... So from the database which has a registration date of the member stored, if I wanted to add 1 month to their registration date and use that with a SHOW IF statement:

(The reason why I am using the timestamp stored in the members database rather then doing the calculation on the page then storing that result in the members table is that I may want to know the actual registration date somewhere else on the website...therefore this approach could have more flexability. especially If I store the "1 month" or "8 Hours" in a table in the database that I could then use as dynamic data...lets say you want to change the 8 hours to something else in the future..in your admin area you could have a page that stores that as well so you wouldnt need to edit the page code manually :)

<?php
$currentdatetime = date('l jS M Y H:i:s');
$storeddatetimeandeighthours = strtotime(date($row_rsMembers['MemberValidTo']). '+1 hour');
?>
<?php echo $currentdatetime; ?>
<BR>
<?php echo date('l jS M Y H:i:s',$storeddatetimeandeighthours); ?>
<p>&nbsp;</p>


<?php
if ("".$currentdatetime ."" < "".$storeddatetimeandeighthours ."") { // WebAssist Show If
?>
<p>This text will only show if under the datetime stored in database is less than 8 hours of current datetime</p>
<?php
} // ("".$currentdatetime ."" < "".$storeddatetimeandeighthours ."")
?>

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...