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
2answers
64 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
70 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
42 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
49 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
759 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
207 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
104 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
89 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
158 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
618 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
42 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
155 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
553 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
27 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
43 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
42 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
78 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
670 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
48 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
57 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
55 views

Countdown click in JavaScript

I did a small countdown clock challenge in JavaScript. Please review it, thanks. ...
3
votes
2answers
151 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
98 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 ...
2
votes
2answers
2k 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
484 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
66 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
45 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 ...
2
votes
1answer
48 views

Using datetime to obtain the time of the next lecture

Often before the lecture starts, and occasionally in the break I like to display a timer with a countdown until the lectures starts/ resumes while playing some lofi-hip hop in the background. While ...
6
votes
4answers
1k views

Convert minutes portion of time to decimal

I am making an hours calculator app. It takes a start time, end time and time taken for lunch. For the start and end time it takes a four-digit hh:mm time. For example: 10:20. I have made a function ...
3
votes
1answer
63 views

Does this R code look ok to expand out to other sites?

I'm after some constructive criticism on my code and maybe some ways to simplify before I expand it to include other sites. I am new to R and coding and have been working on this problem for weeks now....
3
votes
2answers
652 views

Javascript check if server time is greater than or less than 9am EST

I offer same day shipping if the user places an order before 9AM ET. If they place the order after 9AM, same day shipping is unavailable. My server is using UTC time so I need to check if the time is ...
4
votes
1answer
25 views

Creating formatted “[time] [unit] ago” messages from a seconds value

I have this function which calculates how many seconds, mins, hours etc ago a specific time string was. However, the way I have done it consists of a massive if statement block, and it goes through ...
1
vote
1answer
34 views

Check that elements in list follow a specified date-format schema and are not null/na/nan [closed]

I'm practicing some data-analysis and I'm currently checking the integrity of my data. The elements that do not follow my date-schema, should be funneled to a new separate list so I can work on ...
5
votes
2answers
315 views

Removing points from slow riders

I have a CSV like the following. ...
1
vote
1answer
68 views

Working out how many hours worked after a certain time

I am working on some custom rules in a time managment system and need to know how many hours in a shift have been before a certain time (19:00pm) and how many hours after. Shifts can start in the ...
4
votes
1answer
58 views

Apply additions on a base array based on date ranges

please roast my code, I hope this is the good place to look for some advice on where I can improve. Problem definition: Apply modifications on values depending on date ranges. Data: Base array - ...
2
votes
0answers
51 views

Fastest conversion of ISO 8601 string into javascript Date object

On StackOverflow I got a great answer to a question I had about creating a Date object from an ISO 8601 string with the ability to reposition into local time. From there I wanted to see if I could ...
-2
votes
2answers
78 views

Time diff in days [closed]

I have the following snippet: ...
2
votes
1answer
82 views

Parse org-mode clocktable CSVs into time sheets

For my student job, I have been logging work times with the org-mode in emacs for quite some time. Now since I can only work from remote, I figured it would be nice ...
2
votes
0answers
44 views

Generate ISO 8601 Duration String from Two Date Objects

I've written a function which should generate an ISO 8601 duration string, given two Dates as input. ...
1
vote
0answers
58 views

Code for creating a dialog for choosing a date

I have code that creates an AlertDialog to select a date by a user. I ran into a problem that this code began to take up a lot of space. Could you offer ideas on how to shorten this code / put it into ...
4
votes
1answer
45 views

Moving all .xlsx files from the last five days (but not today)

My code works, but it looks very bad. I need to move .xlsx files from the previous days from one folder to another, but I should'nt move the files with today's ...
1
vote
0answers
22 views

Transforming NodaTime ZoneIntervals, version 2

Version 1 may be found here. I have implemented the suggestions by Jon Skeet, plus some of my own. Key differences between versions: ZonedDateRange class is now immutable. LocalDate variables no ...
14
votes
3answers
3k views

Compute the next occurrence of Friday the 13th

How can I get the date of the next occurrence of Friday the 13th? Below is my attempt. It returns the correct results. I think there must be a better way of writing this without checking ...
4
votes
1answer
100 views

Transforming NodaTime ZoneIntervals

Version 2 may be found here. The company I work for has customers around the globe. I work with a time-series database that contains manufacturing process data for each customer site. I was asked ...
4
votes
3answers
86 views

Seconds into readable time information

I had an exercise to solve, written in German. I try to translate it: Write a program that takes an amount of seconds. The program than has to output the number of years, days, hours and seconds. ...
6
votes
2answers
80 views

Combining GPS and vehicle data using for loops and if statements to summarise the distance run under various conditions, much like a excel SUMIF

This is a follow-up to previous post, code is significantly better thanks to comments. The problem is that now it takes 0.25 seconds to iterate 1 row of VehicleEvents through 95000 rows of GPS ...

1
2 3 4 5
20