Skip to content

Instantly share code, notes, and snippets.

@eevmanu
Created March 24, 2026 01:35
Show Gist options
  • Select an option

  • Save eevmanu/72adc27bfb7aade8144023ce5f7078a5 to your computer and use it in GitHub Desktop.

Select an option

Save eevmanu/72adc27bfb7aade8144023ce5f7078a5 to your computer and use it in GitHub Desktop.
gmail api docs to understand date search filter with timestamp
https://developers.google.com/workspace/gmail/api/guides/filtering
Caution: All dates used in the search query are interpreted as midnight
on that date in the PST timezone. To specify accurate dates for other
timezones pass the value in seconds instead:
https://developers.google.com/workspace/gmail/api/reference/rest/v1/users.messages/list
date -d "today 00:00:00 $(date +%Z)" +"%s"
date -d "today 00:00:00 -5" +"%s"
date -d "tomorrow 00:00:00 $(date +%Z)" +"%s"
date -d "tomorrow 00:00:00 -5" +"%s"
@eevmanu

eevmanu commented May 11, 2026

Copy link
Copy Markdown
Author

how to generate timestamps using my local timezone when a date (in rfc 3339 w/ or w/o middle hyphen-minus)

TARGET_DATE="2025-05-11"
TARGET_DATE="20240511"
LOCAL_TZ=$(date +%Z)
date -d "$TARGET_DATE 00:00:00 $LOCAL_TZ" +"%s"
date -d "$TARGET_DATE + 1 day 00:00:00 $LOCAL_TZ" +"%s"

verify with
-> https://www.epochconverter.com/

or

TARGET_DATE="20240511"
LOCAL_TZ=$(date +%Z)
TIMESTAMP_TARGET_DATE=$(date -d "$TARGET_DATE 00:00:00 $LOCAL_TZ" +"%s")
TIMESTAMP_TARGET_DATE_TOMORROW=$(date -d "$TARGET_DATE + 1 day 00:00:00 $LOCAL_TZ" +"%s")
echo "TARGET_DATE TIMESTAMP INIT DATE: $TIMESTAMP_TARGET_DATE"
echo "TARGET_DATE TOMORROW TIMESTAMP INIT DATE: $TIMESTAMP_TARGET_DATE_TOMORROW"
TARGET_DATE_VERIFICATION=$(date -d "@$TIMESTAMP_TARGET_DATE")
TARGET_DATE_TOMORROW_VERIFICATION=$(date -d "@$TIMESTAMP_TARGET_DATE_TOMORROW")
echo "TARGET_DATE VERIFICATION: $TARGET_DATE_VERIFICATION"
echo "TARGET_DATE TOMORROW VERIFICATION: $TARGET_DATE_TOMORROW_VERIFICATION"

@eevmanu

eevmanu commented May 11, 2026

Copy link
Copy Markdown
Author

how to create a search url to share with colleagues to find a specific mail on specific mail account?
assuming you have a google workspace account with domaing pepito.com so <username>@pepito.com

first constraint domain from google account as path parameter

https://mail.google.com/mail/a/pepito.com/#search/...

source: https://knowledge.workspace.google.com/admin/getting-started/customize-a-google-workspace-service-url


second constraint date

input (e.g.): May 08, 2026

calculate after and before timestmap to specific a particular date
(could granularize more but i'll leave it to the reader)

convert May 08, 2026 into rfc3336 format
-> 2026-05-08 or w/o minus signs 20260508

after that calculate the timestamps

TARGET_DATE="20260508"
LOCAL_TZ=$(date +%Z)
date -d "$TARGET_DATE 00:00:00 $LOCAL_TZ" +"%s"
date -d "$TARGET_DATE + 1 day 00:00:00 $LOCAL_TZ" +"%s"

output is

  • after:1778216400
  • before:1778302800

source: https://developers.google.com/workspace/gmail/api/guides/filtering


after that you could use any of the most commen search operators like (e.g.):

from:people_culture@pepito.com

source: https://support.google.com/mail/answer/7190


in this particular example the final url could looks like

https://mail.google.com/mail/a/pepito.com/#search/after%3A1778216400+before%3A1778302800+from%3Apeople_culture%40pepito.com

the pattern entered in the search bar is

after:1778216400 before:1778302800 from:people_culture@pepito.com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment