Link to home
Start Free TrialLog in
Avatar of xenium
xenium

asked on

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

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
SOLUTION
Avatar of Shaun Vermaak
Shaun Vermaak
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of xenium
xenium

ASKER

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

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

Avatar of xenium

ASKER

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
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of xenium

ASKER

Great thanks, that's perfect!
Avatar of xenium

ASKER

PS I have a follow-up I'll post a link to a separate question in a moment
Avatar of xenium

ASKER

This solution opens an additional blank tab by mistake, not a big issue but is there an easy way to avoid this?
Change
window.open(url(),"_blank");

Open in new window

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

Open in new window

Avatar of xenium

ASKER

Great thanks a lot