Creating a dynamic URL - link to results on Airbnb availability for tomorrow

xenium
xenium used Ask the Experts™
on
hi,
I'm looking to create a link to a URL that can update automatically using today's date. Reason is I want to monitor the pricing on my Airbnb listings without having to type in all the search dates every time. So I'd like a URL which is essentially as below but with dates that update to say for example checkin=  ** tomorrow ** &checkout= ** two days later **

https://www.airbnb.co.uk/s/Chippenham--UK?source=hdr&place_id=ChIJXdTdiABjcUgRSYcPSszcRq8&checkin=02-01-2017&checkout=05-01-2017&adults=2&children=0&infants=0&guests=2&room_types%5B%5D=Entire%20home%2Fapt&allow_override%5B%5D=&page=1&s_tag=JioWJWEX


Is there an easy way to do this, perhaps even an expression that the browser itself can parse.

Thanks

PS I've added the javascript topic as I'm interested to learn this and if this is a viable method then this could be a good test
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Shaun VermaakTechnical Specialist
Awarded 2017
Distinguished Expert 2018
Commented:
Just alter the below code
javascript:function url() {
 var date = new Date();
 var y = date.getFullYear(); 
 var m = date.getMonth() +1; 
 if(m < 10){m = '0' + m;}
 var d = date.getDate();
 if(d < 10){d = '0' + d;}
 var date = y + "-" + m + "-" + d;

 return 'https://www.google.com/analytics/web/?authuser=0#my-reports/XXXXXXXX/XXXXXXXXXXX/%3F_u.date00%3D'+ date +'%26_u.date01%3D'+ date +'/';

} window.open(url(),"_blank");

Open in new window


Can also be used as a bookmark.
http://trendblog.net/how-to-create-a-dynamic-bookmark-with-todays-date-in-the-url/

Author

Commented:
Great thanks, that works nicely! I'm new to Javascript so I just need to make some more adjustments for my case.. how would I do today +1 and today + 3? I've done a simple version below but it only works within the same month..

javascript:function url() {
 var date = new Date();
 var y = date.getFullYear(); 
 var m = date.getMonth() +1; 
 if(m < 10){m = '0' + m;}
 var d1 = date.getDate()+1;
 var d2 = date.getDate()+3;
 if(d1 < 10){d1 = '0' + d1;}
 if(d2 < 10){d2 = '0' + d2;}
 var CIdate = d1 + "-" + m + "-" + y;
 var COdate = d2 + "-" + m + "-" + y;

 return 'https://www.airbnb.co.uk/s/Chippenham--UK?source=hdr&place_id=ChIJXdTdiABjcUgRSYcPSszcRq8&checkin='+ CIdate +'&checkout='+ COdate +'&adults=2&children=0&infants=0&guests=2&room_types%5B%5D=Entire%20home%2Fapt&allow_override%5B%5D=&page=1&s_tag=JioWJWEX';


} window.open(url(),"_blank");

Open in new window

Shaun VermaakTechnical Specialist
Awarded 2017
Distinguished Expert 2018

Commented:
Here is updated code
javascript:function url() {
var startDate = new Date();
var y = startDate.getFullYear();
var m = startDate.getMonth() + 1;
if (m < 10) {
  m = '0' + m;
}
var d = startDate.getDate();
if (d < 10) {
  d = '0' + d;
}

var startString = d + "-" + m + "-" + y;

var endDate = new Date();
endDate.setDate(startDate.getDate() + 3);
y = endDate.getFullYear();
m = endDate.getMonth() + 1;

if (m < 10) {
  m = '0' + m;
}
d = endDate.getDate();
if (d < 10) {
  d = '0' + d;
}

var endString = d + "-" + m + "-" + y;
return 'https://www.airbnb.co.uk/s/Chippenham--UK?source=hdr&place_id=ChIJXdTdiABjcUgRSYcPSszcRq8&checkin=' + startString + '&checkout=' + endString + '&adults=2&children=0&infants=0&guests=2&room_types%5B%5D=Entire%20home%2Fapt&allow_override%5B%5D=&page=1&s_tag=JioWJWEX'
} window.open(url(),"_blank");

Open in new window

Should you be charging more for IT Services?

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
Thanks, just a slight change.. start date needs to be tomorrow (today +1) and end date 2 days later (today +3)

I tried editting your code but fell on the first bit

thanks
Technical Specialist
Awarded 2017
Distinguished Expert 2018
Commented:
javascript:function url() {
var startDate = new Date();
startDate.setDate(startDate.getDate() + 1);
var y = startDate.getFullYear();
var m = startDate.getMonth() + 1;
if (m < 10) {
  m = '0' + m;
}
var d = startDate.getDate();
if (d < 10) {
  d = '0' + d;
}

var startString = d + "-" + m + "-" + y;

var endDate = new Date();
endDate.setDate(startDate.getDate() + 2);
y = endDate.getFullYear();
m = endDate.getMonth() + 1;

if (m < 10) {
  m = '0' + m;
}
d = endDate.getDate();
if (d < 10) {
  d = '0' + d;
}

var endString = d + "-" + m + "-" + y;

return 'https://www.airbnb.co.uk/s/Chippenham--UK?source=hdr&place_id=ChIJXdTdiABjcUgRSYcPSszcRq8&checkin=' + startString + '&checkout=' + endString + '&adults=2&children=0&infants=0&guests=2&room_types%5B%5D=Entire%20home%2Fapt&allow_override%5B%5D=&page=1&s_tag=JioWJWEX'
} window.open(url(),"_blank");

Open in new window

Author

Commented:
Great thanks, that's perfect!

Author

Commented:
PS I have a follow-up I'll post a link to a separate question in a moment

Author

Commented:
This solution opens an additional blank tab by mistake, not a big issue but is there an easy way to avoid this?
Shaun VermaakTechnical Specialist
Awarded 2017
Distinguished Expert 2018

Commented:
Change
window.open(url(),"_blank");

Open in new window

to
window.open(url(),"_self");

Open in new window

Author

Commented:
Great thanks a lot

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial