Convert End Date of Sitelink to number

15 views
Skip to first unread message

Tuong Nguyen

unread,
Mar 20, 2015, 7:24:30 AM3/20/15
to adwords...@googlegroups.com
Hi Adwords Experts,
I use this script sitelink.getEndDate(); to get the End Date of the sitelinks but then how can I convert this into a number?
Lets say the End Date of the Sitelink is 18-Mar-15 so I would want it to be '20150318'

Thank you in advance!

Tuong Nguyen

unread,
Mar 22, 2015, 2:27:14 AM3/22/15
to adwords...@googlegroups.com
Anyone has advice?

Daniel Kupi

unread,
Mar 23, 2015, 5:33:37 AM3/23/15
to adwords...@googlegroups.com
Hey Tuong!

You can use .day .year .month on the .getEndDate() to retrieve the values, and with those you can easily create a date string like that, somehow like this:
  while(sitelink.hasNext()) {
   
var currentsitelink = sitelink.next();
   
var date = currentsitelink.getEndDate();

   
if(date != null) {
     
// I used
     
var sitelinkYear = date.year.toString();
     
var sitelinkMonth = (date.month<10) ? "0" + date.month : date.month.toString();
     
var sitelinkDay = (date.day<10) ? "0" + date.day : date.day.toString();
     
var specdate = sitelinkYear + sitelinkMonth + sitelinkDay;
     
Logger.log(specdate);
   
}
 
}

Daniel Kupi

unread,
Mar 23, 2015, 5:35:38 AM3/23/15
to adwords...@googlegroups.com
Sorry forgot the comments so:

  while(sitelink.hasNext()) {
   
var currentsitelink = sitelink.next();
   
var date = currentsitelink.getEndDate();
// check if there is a date object
   
if(date != null) {
// convert the numbers to string
     
var sitelinkYear = date.year.toString();
// if the number is lower than 10 add a 0 to the begining

     
var sitelinkMonth = (date.month<10) ? "0" + date.month : date.month.toString();
// if the number is lower than 10 add a 0 to the begining
     
var sitelinkDay = (date.day<10) ? "0" + date.day : date.day.toString();

Tuong Nguyen

unread,
Mar 23, 2015, 6:56:00 AM3/23/15
to Daniel Kupi via AdWords Scripts Forum
Highly appreciate Daniel!

Tuong Nguyen 

--
-- You received this message because you are subscribed to the Google Groups AdWords Scripts Forum group. Please do not reply to this email. To post to this group or unsubscribe please visit https://developers.google.com/adwords/scripts/community.
---
You received this message because you are subscribed to the Google Groups "AdWords Scripts Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adwords-scrip...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/adwords-scripts/6309331a-f6fe-4b1f-9769-6c1e873e5a07%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages