When you’re working with APIs and different data sources, you’ll notice that everyone wants something in just a slightly different way - and it can lead you to some hair pulling. Naturally, it’d be much easier if you could do it programmatically, right? Well, luckily for you, dashdash has got you covered. Today, we’ll talk about our time functions, how to use mathematical operators with dates, and also how to create date ranges so that your API queries are as precise as you need them to be.
Dashdash currently has the following time functions:
||Get the day from a date.|
||Get the month from a date.|
||Get the year from a date.|
||Create a date using a year, month, and date.|
||Get today’s date in YYYY-MM-DD format.|
||Get the current time and date (a timestamp).|
So I’m guessing it’s pretty simple why you might need to use
TODAY(), but in what case would you need to use
Well, they’re great to use when you need to compare one aspect of the date. For example, if you want to see two companies got funding in the same month of a year, it doesn’t make sense to compare the full dates. Instead, you can use
YEAR() to extract those to parameters and compare them.
If you want to see a real-world example, you should definitely check out our Slack template for automating birthday messages. We use it to evaluate whether the month and day are the same as the current date, and if it is, we send a birthday message on Slack.
Using operators with dates
You can use certain mathematical operators with dates, like greater than (
>) or less that (
<), which is very handy when working with APIs. For example, using the
SEARCH_COMPANIES_BY_FOUNDER_EXITS_CRUNCHBASE() function you might want to get all companies that were founded after 2015 (
>2015) and were sold before and including the year 2017 (
Here’s a list of the operators you should know when it comes to working with dates:
||After this date.|
||After and including this date.|
||Before this date.|
||Before and including this date.|
Lastly, sometimes you might want to include a date range, that is, from one date until another date. For example, from 2015 till 2020. To do this, you need to enclose the dates in square brackets
, and use a semicolon to separate the start and end date. For example:
And putting it into practice again, let’s have a look at the Crunchbase function from before, but modify it to say that we want companies founded between 2010 and 2015:
Note: Working with dates in APIs.
When you enter a date into a cell, or when you create a date using one of our data functions, dashdash converts into a date format. Which makes complete sense. However, when you reference that cell as an integration parameter, the date is passed as a numerical value, and not as a string (in other words, it gets passed as a long number, and not as the date you want). So what should you do then? Well, just use
TO_TEXT() before referencing that cell, and it’ll be formatted perfectly smile:. For example:
And now, equipped with the knowledge of date functions, operators, and ranges, you can build more timely applications . Now, get out there and build !