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
2 votes
1 answer
57 views

Return a set of geodetic coordinates for a particular moment in time

Use case The user is interested in supplying a timestamp of a particular moment in time. This python application will perform two astronomy calculations for a set list of planetary bodies: Calculate ...
Hunter's user avatar
  • 259
3 votes
1 answer
117 views

RANDEVU - Rust crate implementing a simple algorithm I invented

I've created a simple algorithm which I've implemented in Rust and published it as a crate on crates.io. https://crates.io/crates/randevu While I do think my code is pretty clean and idiomatic, I ...
TypicalHog's user avatar
2 votes
2 answers
73 views

Goal: Writing Effective Unit Tests to Ensure a Datetime Conversion To/From Local-UTC Works

As the title lists, I am trying to write an effective unittest suite to ensure that the function that converts a date to UTC from local or vice-versa is doing as planned. But it seems hard because ...
0004's user avatar
  • 121
7 votes
2 answers
271 views

Subtract two lap times (m:ss:fff)

I have two lap time strings I need to subtract, the format is minutes, seconds, milliseconds. This is to compare a new world record time to the previous holder's ...
Soda Party's user avatar
0 votes
1 answer
68 views

Python: Return list of keys if current time is within the range

This is the program I have written to return the list of keys if the current hour is present within the range provided. ...
Tony Montana's user avatar
5 votes
1 answer
1k views

Determine if it is EU summer time in Java

I wanted to write a utility method for learning purposes to determine if a given date (year, month and day) falls within EU summer time or not, without using any of the Java library methods. Is here ...
Tobias Grothe's user avatar
4 votes
1 answer
154 views

Convert durations to a single unit

In the codebase I inherited, I have this function which converts a number and unit into milliseconds: ...
LocustHorde's user avatar
2 votes
2 answers
110 views

Four functions to measure and compare months of duration from one or two dates

I decided to write a few related examples of code, and honestly I don't know if I am overthinking, or just trying to find what is that right way to write functions and how to use them, so that ...
Erasus's user avatar
  • 240
1 vote
2 answers
119 views

Receiving a daily reward

I'm doing a daily reward system on my site. Users can pick up the reward only once a day. The next reward can be picked up the next day, also, only once. When a user visits the site to pick up a daily ...
Andrew Ourst's user avatar
1 vote
3 answers
273 views

List consecutive days

I created this method for consecutive days to be listed with a dash, non-consecutive are separated by “and”. In my UI control I am only getting back a ...
Jefferson's user avatar
  • 359
7 votes
2 answers
2k views

Date Checking in C++

I am working on one of my assignments (Hash Tables) for my Data Structures class(1st year), the assignment focuses on OOP and understanding of Hash Tables. Restrictions: Usage of raw pointers C++11 ...
I_throw_but_dont_catch's user avatar
1 vote
2 answers
481 views

Comparing date in RPGLE

I have an RPG program which processes a file containing records of subscription details of users. Each subscription record has a "valid from date" and "valid to date" - indicating ...
Theju112's user avatar
3 votes
1 answer
1k views

Calculate overlap of two datetime objects

I would like to find out how much time lays in between 22.00 and 6.00 o’clock for a given event per day. So if the event start at 21.00 and ends at 23.59 the result would be 1.59. For a start at 22.00 ...
kiaora's user avatar
  • 31
4 votes
4 answers
3k views

A function that uses a regex to parse date and time and returns a datetime object

The code works, but I think can be simplified, I don't know which specific steps, but my version seems to me quite complicated I build a function that takes a specific string format and returns a <...
Andrea Ciufo's user avatar
2 votes
2 answers
225 views

How to handle optional date parameters?

When creating a function to be reusable throughout the project I came across something strange. After looking at this function it looks very much like it could be refactored. The function should only ...
ARNON's user avatar
  • 401
10 votes
4 answers
4k views

Determine age from given birth date

So this is my first ever attempt so it's obviously bad. There has to be a better way to do this. A big thing I haven't implemented is trying to guarantee the structure of the input(i.e making sure ...
malibooyah's user avatar
3 votes
1 answer
138 views

Generates list of intervals using the biggest different time unit within period

I've created a function to split a period into the biggest different time unit possible. It can be years, months, ...
CIRCLE's user avatar
  • 173
2 votes
2 answers
188 views

Algorithm that prints day, when submitted date

I would love to know your opinion about this algorithm that we wrote in class. I was thinking about how I can optimize it (in terms of size of code/complexity) without using library functions (...
Adrian Rudy Dacka's user avatar
3 votes
1 answer
199 views

PHP Laravel Check if given date is a week or a regular day

I have a problem. In my project the user can copy a menu for a specific day or for a specific week. The value that will be sent to the back-end will be something like: ...
A. Vreeswijk's user avatar
3 votes
1 answer
88 views

Simple ISO date, time and datetime implementation

I am getting started with rust. To get familiar with the language I implemented a datetime library: main.rs ...
Richard Neumann's user avatar
3 votes
2 answers
82 views

Saving and reading the last successful execution as a json-file

I've got some tools that run perdiodically like weekly or monthly that don't support any retry mechanism. In order to increase their chance to succeed in case a database wasn't reachable or some other ...
t3chb0t's user avatar
  • 44.3k
2 votes
1 answer
816 views

Unix epoch seconds corresponding to midnight in a local time zone

I came up with the following function to obtain epoch seconds that correspond to previous midnight in a local time zone: ...
Cattus's user avatar
  • 23
5 votes
1 answer
518 views

Simple TimeStamp class in Python

For a project I'm working on we need a basic time holder class. This is written in CircuitPython, which is a stripped down version of CPython that's missing a number of libraries, including the whole ...
dgnuff's user avatar
  • 263
2 votes
2 answers
56 views

Generating a selection of dates from a given date to the current one, in equal three-month intervals

I need to get a selection of dates from the given to the current, breaking the range of dates into equal parts of 3 months. My code works, but it's clearly not perfect. Give advice on code refactoring....
Novice's user avatar
  • 21
0 votes
1 answer
139 views

timeConversion - C function to convert 12-hour AM/PM format into military time [closed]

I have written a program in C, which given a time in 12-hour AM/PM format, converts it to military time (24 hours). Function Description The timeConversion function should return a new string ...
jr.çhåvez__07's user avatar
0 votes
2 answers
111 views

Search between dates in a WP Query

In the posts I have a date field and a start and end date range. I need to query if it matches date or if it matches between the dates in the range. This Query works, but how can I optimize? ...
cRiSs rOcCa's user avatar
5 votes
1 answer
82 views

Formatting timestamps during autumn DST switchover

I've written code that 99.x% of the time does the same thing as def format(timestamp: datetime) -> str: return timestamp.strftime("%X") but ...
Sören's user avatar
  • 155
3 votes
1 answer
147 views

Constraining a templated method to accept any integral std::chrono::time_point

Recently I was writing a class that had overloaded read methods for various data types. One of the sets of types I wanted to handle were integral ...
md5i's user avatar
  • 133
1 vote
1 answer
84 views

JS function to check if a date is in the correct format

I wrote the following JS function to check if a date comes in the right format and can be used further down in the application ...
Jakub's user avatar
  • 271
4 votes
1 answer
130 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 ...
user19191583's user avatar
1 vote
3 answers
63 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 ...
pee2pee's user avatar
  • 380
2 votes
1 answer
383 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 ...
Digital Farmer's user avatar
1 vote
1 answer
10k 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 ...
TmSmth's user avatar
  • 239
0 votes
2 answers
938 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 ...
Physcofury's user avatar
2 votes
1 answer
798 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 ...
jaried's user avatar
  • 177
2 votes
2 answers
174 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 ...
Damian's user avatar
  • 198
0 votes
1 answer
681 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. ...
1258259's user avatar
-1 votes
1 answer
183 views

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

Given the following dataframe: ...
Carola's user avatar
  • 143
1 vote
0 answers
618 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,...
Nasty Phoenix's user avatar
5 votes
4 answers
8k 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. ...
DumbMathBoy's user avatar
0 votes
2 answers
653 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 ...
BouncexTr's user avatar
1 vote
0 answers
59 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() ...
Memo Haldan's user avatar
6 votes
1 answer
2k 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 ...
user2190492's user avatar
1 vote
0 answers
62 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 ...
Carlo's user avatar
  • 111
3 votes
4 answers
118 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 ...
Fabio Craig Wimmer Florey's user avatar
5 votes
4 answers
1k 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 ...
Handcrafting Country's user avatar
4 votes
3 answers
179 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: ...
oderfla's user avatar
  • 163
1 vote
1 answer
94 views

Parse a selection of date formats

This Bash program parses day, month, year and month and year from arguments: ...
craig's user avatar
  • 173
5 votes
3 answers
3k 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 ...
Stephen Williams's user avatar
3 votes
3 answers
313 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 ...
Daniel Kaplan's user avatar

1
2 3 4 5
21