Greasy Fork is available in English.

Discussions » Creation Requests

Date highlight

§
Posted: 01-01-2018

Date highlight

Possible to get a script that will find a date in the format below and give time since that date?
2016-12-18

Would then be:
2016-12-18 -- 1 year 11 days

Side note if that is to much can some give an example of how to discover a date older than seven days? I have a regex that discovers the date fine, just not sure on how to take it and see if it is older than.

§
Posted: 02-01-2018
Edited: 02-01-2018

Something along the lines of this?

let stringWithDate = "Search this string for the date 2016-12-18 and find out if it is older than 7 days";

// Adjust regex as needed, this only searches for xxxx-(x)x-(x)x
let dateSearch = /\b(\d{4})-(\d{1,2})-(\d{1,2})\b/g;
let firstDate = dateSearch.exec(stringWithDate);

let date = new Date(firstDate[1], firstDate[2]-1, firstDate[3]);
let timeSinceDate = Date.now() - date; // timeSinceDate is in milliseconds
let overWeekOld = timeSinceDate > (1000 * 60 * 60 * 24 * 7);
§
Posted: 03-01-2018

Not able to get it to work.

§
Posted: 03-01-2018

Without knowing what specifically isn't working, there isn't really any way for me to help you further, sorry.

§
Posted: 03-01-2018

Sorry about that I should know better and be more descriptive.

Load script. Goto pages that have the date that I would like to check. Nothing happens.

Nothing happens on this page either. When you run the script what does it show when you see: 2018-01-01

§
Posted: 03-01-2018

Sorry, you asked for an example to check if a date is older than 7 days, so this was just an example snippet. I wasn't providing a complete script, because I thought you implied that you already had most of the script and just needed an example to complete it.

Post reply

Sign in to post a reply.