Solved

Date Comparison Not Working

  • 31 August 2021
  • 4 replies
  • 55 views

Badge

According to the documentation https://developers.amplitude.com/docs/identify-api, I should be able to make date comparisons if in the format ‘YYYY-MM-DD’. I have enriched a few test users with an identify API call that adds some fields in that format, yet I cannot seem to figure out how to make those fields usable in any sort of analysis. (Ex: select all users who performed any event where this date field is greater than or equal to a date that I input). It just shows nothing.

 

Am I doing something wrong within Amplitude or is the data I’m sending possibly in the wrong format?

icon

Best answer by belinda.chiu 1 September 2021, 19:27

View original

4 replies

Userlevel 4
Badge +4

Hi @drewh ! Welcome to the Amplitude Community and thanks for reaching out! 

So it should be the case that you can make date comparisons so long as the format is the ISO 8601 format (YYYY-MM-DDTHH:mm:ss), which will allow you to perform date comparisons in the platform, (e.g. '2016-01-31' > '2016-01-01'). This will also work for datetime values (e.g. '2017-08-07T10:09:08' > '2017-08-07T01:07:00'). Amplitude compares dates as strings. https://developers.amplitude.com/docs/http-api-v2#setting-date-values 

When creating a chart in Amplitude, you should be able to do something like this: https://analytics.amplitude.com/demo/chart/new/2d2k9ac

If you are setting up the chart similarly as I have but the chart is not returning anything, then it is likely that you either are sending the data in the wrong format or perhaps there is no data that is greater than or equal to the date that you input. 

Hope this helps - let me know if you have any questions! 

Badge

Hi @belinda.chiu , thanks for the response. I have tried both standard date format (YYYY-MM-DD) and ISO 8601 (YYY-MM-DDTHH:mm:ss) and the same thing happens with both. Now I’m noticing that if I look at each user individually with the user search, all of these new fields appear with the correct values. But if I do any sort of analysis, only one is registering as having a value for those new fields. 

 

For example, I tested on 10 users. All 10 show the correct details in the user search view, but if I do a user composition chart, it shows that only 1 user has a value for those new fields.

Userlevel 4
Badge +4

Hi @drewh - thanks for sharing! Given that you have tried the two date formats, I might need to see your charts and user profiles to get a better sense of what is going on. I will ask a Community Moderator to help transfer this post into a Support ticket and continue investigations from there!

Userlevel 4
Badge +4

Quick update to provide closure to this post for future viewers: 

Drew and I figured out that the reason why the date comparison was not working is because the user properties were sent in after the event and hence not queryable yet on charts. 

Below are the references that I provided in case other people are curious as well! 

To learn how Amplitude applies user properties to events, see https://help.amplitude.com/hc/en-us/articles/115002380567#applying-user-properties-to-events 
To learn how properties are applied as a filter in charts, see
https://help.amplitude.com/hc/en-us/articles/360016257391-FAQ-Why-is-this-user-counted-under-none-

Reply