Checking dates through script always coming up as zero

55 views Asked by At

I have written a script in Pipedream to get the dates I put in a certain column in my Google Sheets. I want to count them to be able to determine how many time a certain date appears in that column but I still get as count 0 and I do not know where it is going wrong. I tried the 5th of February because I have it appearing 5 times in that column just to test the code but for in the future it needs to check every day how many times the date of today appears.

export default defineComponent({
  async run({ steps, $ }) {
    let count = 0;
    let dates = steps.get_values_in_range.$return_value;
    for (let date of dates) {
      if (date === "02-05-2023") {
        count++;
      }
    }
    return {
      count,
      event: steps.trigger.event,
      get_values_in_range: steps.get_values_in_range.$return_value,
    };
  },
});
2

There are 2 answers

1
Bánh Gạo On

You just need to change one line from your code.

  if (date[0] === "02-05-2023") {
    count++;
  }
0
Aymane Moumni On
import datetime

def handler(pd):
    count = 0
    today = datetime.datetime.now().strftime("%d-%m-%Y")
    get_values_in_range = pd.steps["get_values_in_range"]["$return_value"]
    for range in get_values_in_range:
        if range[0] == today:
            count += 1
    return {
        "count": count,
        "event": pd.steps["trigger"]["event"],
        "get_values_in_range": get_values_in_range
    }

Still thanks for the suggestions guys!