Skip to content

Instantly share code, notes, and snippets.

@federkamm
Created February 20, 2025 16:12
Show Gist options
  • Save federkamm/8b014976754d4b4a1b9c10cb2e4c87fb to your computer and use it in GitHub Desktop.
Save federkamm/8b014976754d4b4a1b9c10cb2e4c87fb to your computer and use it in GitHub Desktop.
convert date to unix timestamp
/* Gregorian calender only, fails in Jan and Feb of year 0 */
int days_since_1970(uint16_t year, uint8_t month, uint8_t day) {
if (month < 3) { month += 12; year--; }
return day + (int)(30.6 * month - 719561.3) + (1461 * year >> 2) - ((year / 100 * 3 + 3) >> 2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment