Skip to content

Instantly share code, notes, and snippets.

@brv00
Created January 25, 2021 07:39
Show Gist options
  • Save brv00/69804af3d87b83d17b8d8772c551d2ee to your computer and use it in GitHub Desktop.
Save brv00/69804af3d87b83d17b8d8772c551d2ee to your computer and use it in GitHub Desktop.
Days between two dates.ipynb
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "function date(d)\n y = d ÷ 10000\n m = d ÷ 100 - 100y\n d = d % 100\n if m < 3\n m += 12\n y -= 1\n end\n y, m, d\nend\ndatetonumber(y, m, d) = Int(365y + floor(y / 4) - floor(y / 100) + floor(y / 400) + floor(30.6m + 1.6) + d)\ndaysbetween2dates(d1, d2) = datetonumber(date(d2)...) - datetonumber(date(d1)...)",
"execution_count": 1,
"outputs": [
{
"data": {
"text/plain": "daysbetween2dates (generic function with 1 method)"
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
]
},
{
"metadata": {
"trusted": true
},
"cell_type": "code",
"source": "daysbetween2dates(20210119, 20210301), #41\ndaysbetween2dates(18210119, 20210119) #73049",
"execution_count": 2,
"outputs": [
{
"data": {
"text/plain": "(41, 73049)"
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
]
}
],
"metadata": {
"gist": {
"id": "",
"data": {
"description": "Days between two dates.ipynb",
"public": true
}
},
"kernelspec": {
"name": "julia-1.4",
"display_name": "Julia 1.4.2",
"language": "julia"
},
"language_info": {
"file_extension": ".jl",
"name": "julia",
"mimetype": "application/julia",
"version": "1.4.2"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment