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

Add 3 months to a posted date in Insert behavior

Thread began 11/19/2021 9:49 am by MagsW | Last modified 11/19/2021 5:06 pm by Ray Borduin | 6 views | 3 replies |

MagsW

Add 3 months to a posted date in Insert behavior

Hi Ray, I've buit an online calendar reminder system which allows users to log specific events. There is one event that occurs quarterly, so rather than asking users to insert the event 4 times I've added a second insert behavior on the page that triggers if the user selects that particular event, and it should automatically add duplicate entries with dates of 3, 6 & 9 months after the entered date - so for example if the user adds the event dated 30 November 2021, I want it to also add entries for 28 February, 30 May and 30 August 2022. I've only added a 3 month increment so far for testing - the insert behavior works but the date doesn't, it's defaulting to a 1970 date. This is my current line from the Insert behavior:

$InsertQuery->bindColumn("EventDate", "t", "".((isset($_POST["datepickerDefault"]) && $_POST["datepickerDefault"]!="" )?date("Y-m-d", strtotime("+3 month", $_POST["datepickerDefault"])):"") ."", "WA_DEFAULT");

I'm assuming I've put the + 3 month in the wrong place - can you advise? Also, I believe there are issues with adding date increments if the date falls on the last day of the month and so will cause problems for dates of 31st (and 29th/30th in the case of February). Do you know how I can get around this?

Sign in to reply to this post

Ray BorduinWebAssist

Your are missing strtotime() around the posted date like:

$InsertQuery->bindColumn("EventDate", "t", "".((isset($_POST["datepickerDefault"]) && $_POST["datepickerDefault"]!="" )?date("Y-m-d", strtotime("+3 month", strtotime($_POST["datepickerDefault"]))):"") ."", "WA_DEFAULT");

Sign in to reply to this post
Did this help? Tips are appreciated...

MagsW

Thanks Ray, I just came back here to say I'd worked it out when I saw your reply - I normally get an email when you reply to posts so not sure why I didn't this time. Anyway, just to confirm that's what I did to get it to work. Ideally I'd like it to return the last day of the month 3 months from now rather than an 'absolute' date (i.e. 3 months from 30 November gives 2 March and not 28 February) but I'm not sure if that's possible?

Sign in to reply to this post

Ray BorduinWebAssist

Use "t" instead of 'd" to get the last day of the month, and start with the first day of the month when adding the months like:


$InsertQuery->bindColumn("EventDate", "t", "".((isset($_POST["datepickerDefault"]) && $_POST["datepickerDefault"]!="" )?date("Y-m-t", strtotime("+3 month", strtotime(date("Y-m-1",strtotime($_POST["datepickerDefault"]))))):"") ."", "WA_DEFAULT");

Sign in to reply to this post
Did this help? Tips are appreciated...

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