Questions tagged [datetime]

DateTime objects in many programming languages describe an instant in time, expressed as a date and time of day. Use on questions about reviewing code involving date/time logic.

Filter by
Sorted by
Tagged with
0
votes
0answers
36 views

Time representation [migrated]

I have the class Time, its purpose is to store time in seconds but for user to use "1:2:3" format, I need to be able to do algebraic operation on it instances, since the whole overriding is ...
1
vote
0answers
21 views

simulation of updating a dataset from real time data

In this code (reproducible example) I want to generate a dataframe composed by random dates in the first col, and by random numbers (in reality they will be generate from a socket) in the second ...
0
votes
0answers
30 views

Creating employee attendance report for some time period

I have written a logic which will get 2 months and get all months between them then I am looping all months and inside every month I am finding all days in that month then looping through these days. ...
2
votes
3answers
52 views

Javascript date / time display

I'm writing a simple start page and it's my first time with JavaScript, my previous background is Python/VBScript. Is it good enough? What best practices should I apply? Should I compress and nest the ...
5
votes
4answers
489 views

Find the earliest date from a series of inputs

I need to find minimal date (year, month, day, hours, minutes, seconds). My code is working, but it looks terrible and it's very long. What can I do to avoid this ladder and make my code readable? (I ...
4
votes
3answers
165 views

Add missing business days in CSV file

I need to fill missing business days (i.e. any days except saturday and sunday) in a series. So let's say I have this array: ...
1
vote
1answer
85 views

Parse a selection of date formats

This Bash program parses day, month, year and month and year from arguments: ...
4
votes
3answers
704 views

Produce a list of every 1st, 3rd, and 5th Friday of each month in a date range

When fridays_135 is called, a list of dates between the start date and end date is produces by date_range. That list is then narrowed down to just the Friday dates and then grouped by month by ...
3
votes
3answers
92 views

Finding the next 9am/pm from now

I have some code that needs to return a datetime of the next 9am or 9pm, UTC. I've figured out some code to do this, but it feels unnecessarily complex to me. Is ...
2
votes
1answer
32 views

Find coherent datetime ranges in postgresql

My Data consists of rows containing a Length/Duration in Minutes, a Begin & EndTime. The precision is 1min (or larger). the table looks something like that: ...
1
vote
1answer
68 views

Find when the shop will next open or close

Intro: I started working three month ago and i have never used JavaScript before, i don't know what is the best practice in JS and i feel like my code can be improved a lot, so i'm here searching for ...
0
votes
2answers
82 views

Year/month difference calculator

My program calculates the user's age in years and months. It takes the user's birth year and month and then the current year and month as input. ...
3
votes
0answers
33 views

Calculate difference between dates and output desired result like (Today, Tomorrow, or 20 Days from now)

I'm writing a task list tracker with VueJS. Each task has a Frequency label (How often it needs to be done), Last completed date label (When the task was completed ...
0
votes
2answers
73 views

Python 3 integer seconds to date-time string convertor

I have written two functions that output a date-time string for any given non-negative integer. The integer is treated as representing total number of seconds in a given time period, the first ...
3
votes
3answers
90 views

Find common timeslots for consecutive days

Imagine you want to reserve a classroom over several days. You get a schedule, from the school, telling you when a certain classroom is still free. To make it easy for your students, you want to ...
1
vote
1answer
140 views

Get result of a scalar-valued SQL function from C#

I do not receive files on holidays; I only receive files on regular days—i.e., non-holidays. I want to skip 2021-09-06 since that's a holiday (Labor Day) and I know I will not receive any files. ...
12
votes
2answers
983 views

Python EU travel visa calculator

Made this basic calculator for travel visa calculation since I was tired of doing it by hand multiple times and online calculators gave mixed results. It prints every day the visa is valid and ...
3
votes
1answer
68 views

UNIX calendar(1) in C

This is a simple implementation of the calendar(1) utility included in some UNIX systems (all BSDs have it, GNU has not). I do not have much experience with ...
0
votes
1answer
99 views

Interpreting abbreviations for days of the week such that they are consecutive days

The code below works, but it seems it could be done better. Is there a better/more efficient way to do this? Given: All days off ("relief days") will be consecutive. Relief days will be ...
2
votes
1answer
144 views

Create a Time class - OOP in Python

Create a Time class. Time is on my side Specification Basic attributes: hour, minute, second and day (default is 0), + getters, + setters (using a decorator) If ...
4
votes
2answers
69 views

For each of the visitors, find if they were present within a time period: code is running slow

I'm working with a pandas dataframe which describes the start and end time of visits. A toy example of the data could be as follows: ...
9
votes
3answers
2k views

Simple day-of-week program

I was doing the following exercise: Create an algorithm which asks the user a number from 1 to 7, and each number represents a day on the week. For example, 1 represents Sunday, 2 represents Monday ...
1
vote
2answers
81 views

Python code to find difference between two dates

I have been working on porting my PowerShell 7 scripts to Python 3.9.5 lately, re-implementing the same logic in a different programming language, keeping what makes it work and removing unnecessary ...
1
vote
1answer
57 views

Pandas merge a "%Y%M%D" date column with a "%H:%M:%S" time column

I have a dataframe with a column composed by date object and a column composed by time ...
0
votes
1answer
166 views

Fill missing dates into array of np.datetime

Here is the problem: Given an array of a non-continuous sequence of dates. Make it a continuous sequence of dates, by filling in the missing dates. ...
10
votes
2answers
1k views

Return quarters of current year

I build this simple function, trying to use PEP 8 Style, something that I discovered recently thanks to this previous question. The function works, but I was wondering if there is a better way to do ...
0
votes
1answer
494 views

Code to generate a random date of birth which will always represent an age less than 18 years from current date

I want to generate a random date of birth [mm/dd/yyyy]which will represent an age equal to less than 18years old My requirement is to dynamically generate test data [date of birth] to negatively test ...
3
votes
3answers
110 views

Add 10000 days to a date

I'm currently doing old exams from my course to train for my upcoming exam. What I'm wondering is about a code block which I will specify after I've presented the different files with code. //...
0
votes
2answers
111 views

Extension method to get the Sunday date from current date based on weekOffset

I want to write an extension method for getting Sunday Date based on weekOffset and current date. For example if weekOffset value is 1 that means next week sunday date and if weekOffset is 2 that ...
4
votes
1answer
307 views

Stop Watch class in C++ using chrono

I have written a class that acts like a stopwatch using C++11's std::chrono library. I wrote this because I find it difficult to benchmark my cpp code properly, ...
10
votes
1answer
619 views

Printing the date of any day of the week as it occurs between two set dates

This a block of code taken from a program I am working on that creates multiple files. This part of the code is to create files and sort them by date by appending the date to the file name. User ...
0
votes
1answer
43 views

DateTime Extension for entering historical dates, i.e. birthdays

This class is intended to fulfill these requirements: Output in Y-m-d H:i:s format Allow dates to be entered as m-d-Y or m-d-y Complain if an invalid birthdate is entered (i.e., in the future or ...
4
votes
2answers
175 views

Java - General purpose String to LocalDateTime parser

I have a couple of general purpose LocalDateTime parser methods I wrote to handle Dates flowing between a number of legacy XML based processing pipelines over to a modern Spring Boot, Mongo ...
6
votes
2answers
1k views

Checking if an array of dates are within a date range

I created a dates_in_range() function which checks if all of the dates passed to it ($dates array) are within ...
2
votes
1answer
28 views

Input any time, output timezones that are currently that time

I made a program that will take in a time and a weekday, and return which parts of the world are at times closest to the one specified. Part of the program focuses on extracting a date and country out ...
0
votes
1answer
97 views

JavaScript date format string to php date format string convert

Please find the following scenario, I've dynamic JS date format string from API but I am looking for the best way to convert the format that accepts in PHP date format. For now, I wrote it my own way ...
2
votes
1answer
45 views

JavaScript function for the get the formatted date of tomorrow

I need a JavaScript-function which always computes the date of the next day. Then returns the date as a string, formatted in the way: dd.mm.yyyy I wrote this code: ...
2
votes
0answers
82 views

Creating calendar - Speeding up PHP script

I'm working on a calendar for my office. Every people has his own column and there is a line for every day. There are some periodic date, where, for example, given people have to be working on the ...
9
votes
4answers
833 views

Calculating parking fees, given start and end timestamps

Since I have just started Javascript, I am trying to solve a few problems and improve myself. I encountered such a question. I tried to do everything step by step from the question, but I do not think ...
1
vote
1answer
57 views

PowerShell - calculate occurences of Friday the 13th between (including) two given years with builtin and without builtin

It's me again, talented programming beginner fast-learner, so I have overcomed yet another self-imposed programming challenge, I have developped two algorithms to calculate occurrences of Friday the ...
1
vote
0answers
126 views

PowerShell - Calculating date difference between two given dates in days without builtin and with builtin

The title says it all, I have written two scripts to calculate dates to test my abilities in programming, one from scratch, without [DateTime], New-TimeSpan and even [math]::Ceiling, and it's really ...
3
votes
1answer
35 views

Calculating difference between cached period and requested

There is a remote resource containing datasets arranged by time, data is static and doesnt change. Whenever we are going to fetch anything from there we will be saving it in our cache. User might ...
2
votes
1answer
58 views

Countdown click in JavaScript

I did a small countdown clock challenge in JavaScript. Please review it, thanks. ...
3
votes
2answers
237 views

Calculate age given the birth date in the format YYYYMMDD

Here is method to calculate age given the birth date in the format YYYYMMDD. ...
2
votes
1answer
162 views

DateTime range splitting algorithm

I have the algorithm which splits DateTime range into multiple ranges based on night time range. For example: Night start: 22:00, Night end: 06:00 Start time: 2020-10-26 21:00:00 End time: 2020-10-27 ...
3
votes
2answers
4k views

Checking if the access token is valid or expired

Basically, the server gives me a token object. I am planning to check the token on the client if it is expired/valid before ...
2
votes
2answers
851 views

Date Detection with Python RegEx

its a practice project from "Automate the Boring stuff with Python" book. i am an intermediate level Python programmer and i tried to solve this problem with less code as possible. This code ...
3
votes
0answers
84 views

Calculate age from birthday in C#

For a project I'm working on, I need to calculate the age of users based on their birthday (which is a DateTime object). with a few requirements: the output must be in french (the entire project is ...
3
votes
1answer
50 views

ways to code for better speed of processing date comparisions / slicing in python

I wrote the below code to convert a long data frame containing start and end date event spans into a daily df with rows for each day: output: ...
-2
votes
1answer
59 views

what is the best practice concerning opening CSV files in python [closed]

I am looking for the best way to save regular data from a series of sensors to a CSV file. the program will be reading every sensor once a minute 24/7 and needs to report the results to a CSV file ...

1
2 3 4 5
21