From 1727ba3ebde3981b2b086a71bd3d78529c22c102 Mon Sep 17 00:00:00 2001 From: Florent Ravenel Date: Thu, 16 Nov 2023 09:25:26 +0100 Subject: [PATCH 1/2] feat(Datetime): Add Get first and last day of the current week --- ...rst_and_last_day_of_the_current_week.ipynb | 241 ++++++++++++++++++ 1 file changed, 241 insertions(+) create mode 100644 Datetime/Datetime_Get_first_and_last_day_of_the_current_week.ipynb diff --git a/Datetime/Datetime_Get_first_and_last_day_of_the_current_week.ipynb b/Datetime/Datetime_Get_first_and_last_day_of_the_current_week.ipynb new file mode 100644 index 0000000000..f84ccb7db4 --- /dev/null +++ b/Datetime/Datetime_Get_first_and_last_day_of_the_current_week.ipynb @@ -0,0 +1,241 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "id": "73f2337a-d83b-4fc0-ad5e-25e6afa0a9d3", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "\"Naas\"" + ] + }, + { + "cell_type": "markdown", + "id": "d21f3261-0ede-4a5c-b50b-eb566a042090", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "# Datetime - Get first and last day of the current week" + ] + }, + { + "cell_type": "markdown", + "id": "bfed5b78-8d35-460e-a6d0-9115cd52762c", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Tags:** #datetime #python #week #current #first #last" + ] + }, + { + "cell_type": "markdown", + "id": "091e87f5-0fc6-4f64-a5e7-82cc040e9dcb", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Author:** [Florent Ravenel](https://www.linkedin.com/in/florent-ravenel/)" + ] + }, + { + "cell_type": "markdown", + "id": "244012bd-24b4-4b92-9ebe-06c3b85faf85", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Last update:** 2023-11-16 (Created: 2023-11-16)" + ] + }, + { + "cell_type": "markdown", + "id": "cff29e68-62c5-4a3b-af31-fa00579962b3", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**Description:** This notebook shows how to get the first and last day of the current week using Python. It is usefull for organizations to quickly get the start and end date of the current week." + ] + }, + { + "cell_type": "markdown", + "id": "ce3aede6-73cb-45a1-bf97-205a30137421", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "**References:**\n- [Python datetime](https://docs.python.org/3/library/datetime.html)\n- [Python timedelta](https://docs.python.org/3/library/datetime.html#timedelta-objects)" + ] + }, + { + "cell_type": "markdown", + "id": "73332542-a39b-4ff6-b287-b2728ed48fd0", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Input" + ] + }, + { + "cell_type": "markdown", + "id": "aab415f0-7975-4c24-b356-57adf8c02b2b", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Import libraries" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "cc0cb25c-fb3e-41b0-954b-9489595f8824", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": "import datetime", + "outputs": [] + }, + { + "cell_type": "markdown", + "id": "e401b9b9-7fde-4a35-8148-84f5e9cc57f3", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Setup variables\n- `today`: today's date" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "ee9859fc-e30d-4ed5-a080-cb767ef7f0e0", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": "today = datetime.date.today()", + "outputs": [] + }, + { + "cell_type": "markdown", + "id": "7ee18647-21fa-483c-9df3-9205ed865cb0", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Model" + ] + }, + { + "cell_type": "markdown", + "id": "407f8d0f-013d-403e-bdf1-1a3ce07cba24", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Get first and last day of the current week" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "cac70dd2-7c55-43eb-8d37-706aea280190", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": "# Get the day of the week as an integer, where Monday is 0 and Sunday is 6\nday_of_week = today.weekday()\n# Subtract day_of_week from today to get the first day of the current week\nfirst_day_of_week = today - datetime.timedelta(days=day_of_week)\n# Add 6 to get the last day of the current week\nlast_day_of_week = first_day_of_week + datetime.timedelta(days=6)", + "outputs": [] + }, + { + "cell_type": "markdown", + "id": "bd03ed57-8bd2-4d00-89f3-c414c6bae648", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "## Output" + ] + }, + { + "cell_type": "markdown", + "id": "88375c34-dfee-4736-a79a-1b3fcb9a0da9", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + "### Display result" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "94f5f1a5-26c2-4db8-930d-d606d42b24f5", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": "print(f\"First day of the current week: {first_day_of_week}\")\nprint(f\"Last day of the current week: {last_day_of_week}\")", + "outputs": [] + }, + { + "cell_type": "markdown", + "id": "3c8c9b5a-2210-4833-b066-f83de19dbb0a", + "metadata": { + "papermill": {}, + "tags": [] + }, + "source": [ + " " + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.6" + }, + "widgets": { + "application/vnd.jupyter.widget-state+json": { + "state": {}, + "version_major": 2, + "version_minor": 0 + } + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} \ No newline at end of file From 72840f6896499b50ad32aa68052847d3dba7433c Mon Sep 17 00:00:00 2001 From: Florent Ravenel Date: Thu, 16 Nov 2023 09:31:00 +0100 Subject: [PATCH 2/2] feat: update description --- ...rst_and_last_day_of_the_current_week.ipynb | 86 +++++++++++++++---- 1 file changed, 70 insertions(+), 16 deletions(-) diff --git a/Datetime/Datetime_Get_first_and_last_day_of_the_current_week.ipynb b/Datetime/Datetime_Get_first_and_last_day_of_the_current_week.ipynb index f84ccb7db4..7e36558fbc 100644 --- a/Datetime/Datetime_Get_first_and_last_day_of_the_current_week.ipynb +++ b/Datetime/Datetime_Get_first_and_last_day_of_the_current_week.ipynb @@ -63,7 +63,7 @@ "tags": [] }, "source": [ - "**Description:** This notebook shows how to get the first and last day of the current week using Python. It is usefull for organizations to quickly get the start and end date of the current week." + "**Description:** This notebook shows how to get the first and last day of the current week using Python." ] }, { @@ -74,7 +74,9 @@ "tags": [] }, "source": [ - "**References:**\n- [Python datetime](https://docs.python.org/3/library/datetime.html)\n- [Python timedelta](https://docs.python.org/3/library/datetime.html#timedelta-objects)" + "**References:**\n", + "- [Python datetime](https://docs.python.org/3/library/datetime.html)\n", + "- [Python timedelta](https://docs.python.org/3/library/datetime.html#timedelta-objects)" ] }, { @@ -101,14 +103,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "id": "cc0cb25c-fb3e-41b0-954b-9489595f8824", "metadata": { + "execution": { + "iopub.execute_input": "2023-11-16T08:30:01.209606Z", + "iopub.status.busy": "2023-11-16T08:30:01.209158Z", + "iopub.status.idle": "2023-11-16T08:30:01.219278Z", + "shell.execute_reply": "2023-11-16T08:30:01.218709Z", + "shell.execute_reply.started": "2023-11-16T08:30:01.209532Z" + }, "papermill": {}, "tags": [] }, - "source": "import datetime", - "outputs": [] + "outputs": [], + "source": [ + "import datetime" + ] }, { "cell_type": "markdown", @@ -118,19 +129,29 @@ "tags": [] }, "source": [ - "### Setup variables\n- `today`: today's date" + "### Setup variables\n", + "- `today`: today's date" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "id": "ee9859fc-e30d-4ed5-a080-cb767ef7f0e0", "metadata": { + "execution": { + "iopub.execute_input": "2023-11-16T08:30:01.220769Z", + "iopub.status.busy": "2023-11-16T08:30:01.220545Z", + "iopub.status.idle": "2023-11-16T08:30:01.411130Z", + "shell.execute_reply": "2023-11-16T08:30:01.410530Z", + "shell.execute_reply.started": "2023-11-16T08:30:01.220739Z" + }, "papermill": {}, "tags": [] }, - "source": "today = datetime.date.today()", - "outputs": [] + "outputs": [], + "source": [ + "today = datetime.date.today()" + ] }, { "cell_type": "markdown", @@ -156,14 +177,28 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "id": "cac70dd2-7c55-43eb-8d37-706aea280190", "metadata": { + "execution": { + "iopub.execute_input": "2023-11-16T08:30:01.412274Z", + "iopub.status.busy": "2023-11-16T08:30:01.412096Z", + "iopub.status.idle": "2023-11-16T08:30:01.532052Z", + "shell.execute_reply": "2023-11-16T08:30:01.531396Z", + "shell.execute_reply.started": "2023-11-16T08:30:01.412254Z" + }, "papermill": {}, "tags": [] }, - "source": "# Get the day of the week as an integer, where Monday is 0 and Sunday is 6\nday_of_week = today.weekday()\n# Subtract day_of_week from today to get the first day of the current week\nfirst_day_of_week = today - datetime.timedelta(days=day_of_week)\n# Add 6 to get the last day of the current week\nlast_day_of_week = first_day_of_week + datetime.timedelta(days=6)", - "outputs": [] + "outputs": [], + "source": [ + "# Get the day of the week as an integer, where Monday is 0 and Sunday is 6\n", + "day_of_week = today.weekday()\n", + "# Subtract day_of_week from today to get the first day of the current week\n", + "first_day_of_week = today - datetime.timedelta(days=day_of_week)\n", + "# Add 6 to get the last day of the current week\n", + "last_day_of_week = first_day_of_week + datetime.timedelta(days=6)" + ] }, { "cell_type": "markdown", @@ -189,14 +224,33 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "id": "94f5f1a5-26c2-4db8-930d-d606d42b24f5", "metadata": { + "execution": { + "iopub.execute_input": "2023-11-16T08:30:01.533126Z", + "iopub.status.busy": "2023-11-16T08:30:01.532868Z", + "iopub.status.idle": "2023-11-16T08:30:01.819949Z", + "shell.execute_reply": "2023-11-16T08:30:01.819245Z", + "shell.execute_reply.started": "2023-11-16T08:30:01.533099Z" + }, "papermill": {}, "tags": [] }, - "source": "print(f\"First day of the current week: {first_day_of_week}\")\nprint(f\"Last day of the current week: {last_day_of_week}\")", - "outputs": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "First day of the current week: 2023-11-13\n", + "Last day of the current week: 2023-11-19\n" + ] + } + ], + "source": [ + "print(f\"First day of the current week: {first_day_of_week}\")\n", + "print(f\"Last day of the current week: {last_day_of_week}\")" + ] }, { "cell_type": "markdown", @@ -238,4 +292,4 @@ }, "nbformat": 4, "nbformat_minor": 5 -} \ No newline at end of file +}