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
4 votes
1 answer
97 views

Check how many days a country has been independent

I have been using a website called 'CSNewbies' to learn Python and one of the tasks was to create a way for a user to check how many days a country has been independent. The countries are limited to ...
user avatar
1 vote
3 answers
46 views

Removing medications older than 180 days ago from a list

I have the following code which removes a dict from a list of dicts in Python based on ...
user avatar
  • 360
2 votes
1 answer
46 views

Clear output line in terminal after use for countdown (different length strings)

The method to overwrite the same line is well known and I use it for countdown, but what about when the next output string has a different size and will be generated by a single print? That's the ...
user avatar
0 votes
1 answer
45 views

Convert string to date C++

New to C++ here, by combining different pieces of code I've found, i came with this solution below to convert a date in string to a date object. It works as I want but I'm not certain to do the ...
user avatar
  • 209
0 votes
0 answers
10 views

Custom duration input component

I would love some pointers in terms of clean code, performance and maybe edge cases that I missed. Component Template ...
user avatar
  • 229
0 votes
2 answers
63 views

12 hour to 24 hour time conversion

doing hackerrank challenges and been learning python3 for a month now, made this code to convert and return 12 hour to 24 hour time format in one of the challenges ...
user avatar
0 votes
0 answers
42 views

Deep Reinforcement Learning training on gym data

Related question: Extract the last row in a dataframe with a timestamp before some given time This is part of the code for Deep Reinforcement Learning training on a standards-based gym env. What I ...
user avatar
  • 135
2 votes
1 answer
85 views

Extract the last row in a dataframe with a timestamp before some given time

Related questions: I need to take specific row from different df to generate new df. How can I make my code faster? I want to take the last data before the specified time from different time intervals ...
user avatar
  • 135
2 votes
2 answers
122 views

Generate date_range for string intervals like 09:00-10:00/11:00-14:00/15:00-18:00 and calculate the working minutes

I'm a bit new in python and I'm trying to achieve what I can't with VBA, get things faster. I have large datasets like this in the source(just a sample): This is done also by python and it's a CSV ...
user avatar
  • 178
0 votes
1 answer
71 views

Calculate working Hours in given shift time

This is simple program to calculate working hours in given shift.. It is also return user sessions and presence of user shift. while this works fine. I would like suggestion to improve it. ...
user avatar
-1 votes
1 answer
41 views

Extraction of subsets by date and intervals from a dataframe with a specific date format

Given the following dataframe: ...
user avatar
  • 121
1 vote
0 answers
181 views

deprecated strftime in PHP 8.1

I saw that strftime is deprecated in PHP 8.1. I saw I can use a class include in intl but I'm not sure to understand how to use It. On my site I use this function with the array $datesToConvert{020222,...
user avatar
5 votes
4 answers
1k views

Get random time between two time inputs

This code takes two times as input and then calculates a random time between the two inputs. ...
user avatar
0 votes
2 answers
142 views

Create a formatted calendar

I'm working on a project that creates a calendar based on user input of a month and a year. With that information, the code should count the number of days in that month and output a calendar. I would ...
user avatar
1 vote
0 answers
37 views

Calculate time interval excluding breaks

I have a solution for a question I asked on SO: I am trying to create a database where I also need to find the time difference inside a record. However, timediff() ...
user avatar
1 vote
0 answers
63 views

Date range generator

An app has a feature that's much like any calendar application (like the Outlook calendar for example). Consequently, I need to do a lot of date logic. I wrote a class with date calculation methods ...
user avatar
1 vote
0 answers
27 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 ...
user avatar
  • 111
0 votes
0 answers
86 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. ...
user avatar
2 votes
3 answers
67 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 ...
user avatar
5 votes
4 answers
566 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 ...
user avatar
4 votes
3 answers
167 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: ...
user avatar
  • 163
1 vote
1 answer
90 views

Parse a selection of date formats

This Bash program parses day, month, year and month and year from arguments: ...
user avatar
  • 173
5 votes
3 answers
886 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 ...
user avatar
3 votes
3 answers
100 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 ...
user avatar
2 votes
1 answer
34 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: ...
user avatar
  • 121
1 vote
1 answer
123 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 ...
user avatar
0 votes
2 answers
100 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. ...
user avatar
8 votes
4 answers
869 views

Check if calendar week number falls within two other week numbers

I want to check with Javascript if a week number (with year) is within two other week numbers. Example data: Year-Week ...
user avatar
  • 183
3 votes
0 answers
36 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 ...
user avatar
  • 131
0 votes
2 answers
87 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 ...
user avatar
3 votes
3 answers
128 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 ...
user avatar
1 vote
1 answer
257 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. ...
user avatar
12 votes
2 answers
987 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 ...
user avatar
  • 121
3 votes
1 answer
73 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 ...
user avatar
  • 854
0 votes
1 answer
103 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 ...
user avatar
  • 341
2 votes
1 answer
315 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 ...
user avatar
4 votes
2 answers
71 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: ...
user avatar
  • 141
9 votes
3 answers
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 ...
user avatar
1 vote
2 answers
103 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 ...
user avatar
1 vote
1 answer
78 views

Format multiple dates to look good in text, using functional approach

I had a piece of code that solved really simple problem - it formated two dates to look better on a webpage. It looked like this: ...
user avatar
  • 11
1 vote
1 answer
92 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 ...
user avatar
0 votes
1 answer
287 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. ...
user avatar
10 votes
2 answers
2k 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 ...
user avatar
0 votes
1 answer
756 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 ...
user avatar
3 votes
3 answers
121 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. //...
user avatar
  • 51
0 votes
2 answers
115 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 ...
user avatar
  • 1
4 votes
1 answer
613 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, ...
user avatar
10 votes
1 answer
623 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 ...
user avatar
  • 147
0 votes
1 answer
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 ...
user avatar
4 votes
2 answers
188 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 ...
user avatar

1
2 3 4 5
21