We’re rewarding the question askers & reputations are being recalculated! Read more.

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
1
vote
0answers
65 views

Running some code every day at certain times

I am currently developing a windows service in C# which is supposed to run a data import every day at configurable times. For this purpose I have created a class "ExecutionTime" which contains the ...
1
vote
2answers
63 views

Date Class, implemented

I'm implementing this date class based on <ctime> I'll appreciate your comments, critics and advice. Please review, thank you!. Date.h ...
9
votes
1answer
1k views

C function to check the validity of a date in DD.MM.YYYY format [closed]

I was tasked with writing a function, that checks whether a date is valid in the following format: DD.MM.YYYY. Here's what I wrote: ...
6
votes
1answer
224 views

Interpret a date from a string of digits

I developed a function that, from a given sequence of digits, extracts the date and reformat it. This is the code: ...
0
votes
0answers
21 views

SQL Server - Flagging overlapping time entries and calculating time without overlaps

Here's my example set up in rextester. https://rextester.com/LROA87361 I have the following table in gray (the rightmost 2 columns are for explanation). As you can see an employee's time entries ...
4
votes
2answers
45 views

Simple timestamping filter in C

I wrote a simple timestamping filter that prepends each line with the UNIX timestamp in nanosecond precision as returned by clock_gettime, as well as the difference to the previous timestamp. ...
0
votes
2answers
74 views

Project Euler problem #19: counting months that began on Sundays

You are given the following information, but you may prefer to do some research for yourself. 1 Jan 1900 was a Monday. Thirty days has September, April, June and November. All the rest ...
4
votes
3answers
369 views

Python process tracklist, get cumulative timestamp of each track

The code below parses a tracklist (sample input below) and generates a six-member tuple, including cumulative timestamps in mm:ss. (sample output at bottom). ...
10
votes
2answers
1k views

Converting time in number of minutes past midnight to HH:MM format

This program is a clock that only displays minutes passed since midnight. This program is supposed to be really simple but because of some "aesthetic bug", I wrote quite a lot if-else statements that ...
4
votes
1answer
126 views

Cython functions for generating NumPy date ranges

I have rewritten my python code in cython in order to speed up it quite a bit. However after checking the code in jupyter it seems that part of it is still compiled as python code, therefore its not ...
2
votes
1answer
57 views

List of dates with special formatting

I have a code that calls many times a function returning a list of the dates between two dates formatted as ('0001-01-01 00:01:00'),('0001-01-02 00:01:00'), ... The current solution is: ...
3
votes
1answer
38 views

How to properly get values from multidimensional object

Output should be an object ({cal: val}), with soonest possible time throughout all calendars recommended times from the data. My question is: is this approach over complicated and if so, what should ...
3
votes
1answer
61 views

Daily SQL job to delete records older than 24 hours

Below is a delete job to delete 1M+ records daily and takes 13 hours to complete and sometimes more than that. I need to optimize this. The table tblcalldatastore is being inserted 24*7 through a ...
3
votes
1answer
84 views

Date format function in JavaScript

How can I improve the date format function. I have written in javascript (ES5/ES6)? This code is just a part of an exercise. ...
2
votes
2answers
165 views

HackerRank Time Conversion solution

The challenge (PDF) is to convert a time from 12-hour format (hh:mm:ssAM or hh:mm:ssPM) to 24-hour format. This is my solution, ...
2
votes
0answers
45 views

Calculate reservation cancellation penalty based on date difference

The website I'm developing allows customers to book an appointment. They can also cancel their appointment with the following rules: if the appointment is cancelled between 48 hours and 1 hour in ...
11
votes
3answers
2k views

Convert a string like 4h53m12s to a total number of seconds in JavaScript

At the moment I have this: ...
4
votes
1answer
188 views

Difference between dates in Months and Days [closed]

I've written a function that returns how many Months and Days are between two dates. I want to respect calendar month boundaries, but I'm ignoring time as it's not relevant for my needs. I've got the ...
5
votes
2answers
104 views

Algorithm in getting total garnered hours for student

I'm calculating now the total garnered hours student get in school using php. (Same concept in getting the total work hours in employee for timesheets) So I have an array ...
3
votes
1answer
239 views

Merge dataframes on timestamps and time intervals using data.table in R

I have two dataframes (x and y) that I need to join, conditional on the timestamp in ...
2
votes
1answer
43 views

Project Euler # 19 Counting Sundays in Python

You are given the following information, but you may prefer to do some research for yourself. 1 Jan 1900 was a Monday. Thirty days has September, April, June and November. All the rest have ...
6
votes
1answer
130 views

Calculate working hours using Python

This is a simple boilerplate / template for a bigger program (I hope), either linked to a DB or including a GUI frontend using PYQT or TKinter. This is just a little tool I wrote to keep track of my ...
2
votes
0answers
69 views

Code to email past-due accounts

I am using this syntax to query a table and return a record set and if the number of times total the customer has been emailed is less than 5, send an email with a canned response. If the number of ...
2
votes
2answers
79 views

“When to take medicine” CodeChef Challenge MEDIC

I just submitted this code to solve the "When to take medicine" challenge on CodeChef: ...
4
votes
1answer
36 views

Calculate implicit dates

I need help to simplify this code about implicit date calculation. The context: I have sentences with implicit and explicit dates. For instance: "From the 5th to the 7th of September 2017, the ...
7
votes
3answers
222 views

Convert integer to full text string duration

I have a function I have written in VB for use in SSRS 2012. It takes an integer and converts it to full text duration - for example 900 becomes "15 minutes", 9000 becomes "2 hours 30 minutes", and ...
1
vote
2answers
179 views

Parse date format in Pandas using Python

I have a column in a Pandas Dataframe containing birth dates in object/string format: 0 16MAR39 1 21JAN56 2 18NOV51 3 05MAR64 4 05JUN48 I want to ...
4
votes
1answer
38 views

Time interval class that enhances constructor argument handling of its parent class

I am making a subclass of a well-established python class: pendulum.Period, which overrides both __new__ and ...
2
votes
1answer
35 views

Date prompt React.js component

I have created a date component (working GIF at the bottom; please ignore the styling). There isn't a problem with the working of the code but rather the code I wrote seems messy and something hard ...
4
votes
1answer
48 views

List of previous and upcoming months to a given date (year and month)

I need a menu with buttons of months previous and after a given month, something like this: | month | month | month | current month | month | month | month | Can this function further be improved? ...
2
votes
1answer
69 views

Static Methods for Dealing with Conversions from and to UTC

I asked this question over at stackoverflow but was told it may be better suited here. So I absolutely want to store DateTimeOffset objects in UTC format. To ...
4
votes
1answer
42 views

Generic calendar which can hold Mayan, Babylonian, Fantasy, Gregorian calendars

I have created this generic calendar class which I call a TimePeriodGrouping. It can contain a series of interlocking time periods (i.e. years, months, days, hours...). When time is added to one of ...
7
votes
1answer
2k views

Python program to convert a 24 hour format to 12 hour format

Given a string in a 24 hour format the program outputs a 12 hour format. The rules are: The output format must be 'hh:mm a.m.' if it represents before midday and 'hh:mm p.m.' after midday When the ...
6
votes
1answer
155 views

Calculate the day when Date is given as input using the Doomsday algorithm

Was too bored in holidays...here's a code which finds the day of the week using the algorithm in this video. Please give a logical date in the correct format cause I didn't account for improper inputs ...
4
votes
0answers
67 views

Game clock with configurable rate

Edit: Licensed source can be found here. The intent behind this class is to allow different game systems to run at their own clock rate. The physics integration rate should not be connected to the ...
2
votes
1answer
361 views

Python script for sorting a huge log file based on timestamps

I want to write a python script to sort a huge file, say 2 GB in size, which contains logs in the following format - ...
4
votes
1answer
33 views

Calculating elapsed time

The code below compares recv.rcpt_dtim (which is a datetime type) against the current date/time. It calculates an elapsed time resulting in hours and minutes formatted like: "04:22". It took me a ...
0
votes
1answer
82 views

Hotel Booking functionality - handling UTC dates & timezones

People here often ask to share as much code as possible. My app is just a sandbox, a typical freshly created AspNetCore + Angular template without much code. So please don't blame me - I provide ALL ...
2
votes
0answers
26 views

Getting service rate based on time/day of service

I have a long roster where I'd like to categorize the rates by time/day of service. Most shifts ends the same date but there are some special cases where the shift ends on a different date. I have to ...
2
votes
1answer
40 views

Determine if a String can be parsed to LocalDateTime or Int

I have the following kotlin function that takes in a string "value", then attempts to parse "value" as both a LocalDateTime and an Int. It returns a Pair of the parsed value of "value" and an enum ...
3
votes
1answer
47 views

Grouping dates by weeks using reduce()

I am trying to implement a function groupWeeks(dates) using reduce that allows me to group an array of objects ...
3
votes
1answer
50 views

Bar graph of Easter date distribution

Computing Easter for a given year is a classic computational problem. It is also one of the few cases when code seems to just have to live with magic numbers. Alternative to magic numbers: Decoding ...
0
votes
1answer
97 views

Formatting milliseconds as days, hours, minutes, and seconds [closed]

This is a function which aims to convert an amount of milliseconds to a more human-interpretable Day(s) Hour(s) Minute(s) Second(s) format: ...
2
votes
1answer
40 views

Get _m_s time format from milliseconds value

I could have any value in milliseconds like: 1040370 I must alert a specific converted time format : _m_s (ie:17m20s) Here ...
2
votes
2answers
64 views

Class to transform milliseconds to current date

The task Given a variable of type long with the number of milliseconds from January 1, 1970 until a later date (CurrentDate). Build a class for get the year, month, day of year, day of month, hour, ...
2
votes
1answer
50 views
2
votes
1answer
49 views

Determining daylight-saving time in Central European Time

(We are on SQL Server 2008). The following constellation: Our applications passes date&time around (in the most horrible way possible). We want to simplify this. Instead of a culture-specific ...
3
votes
2answers
39 views

Parse a date in various formats

I have a problem similar to the question, namely reading in text which describes a date - in various formats. I want to use the parseTimeM function from ...
1
vote
1answer
46 views

Select depart date, 5 days from today and return date, 6 days from today in Selenium

I am automating a scenario of flight booking on Cleartrip.com(https://www.cleartrip.com/flights) in which I have to enter depart date, 5 days from today and return date, 6 days from today. I have ...
2
votes
1answer
68 views

Getting the current timestamp and compute the timestamp difference in minutes

I have this code to get the current Timestamp and compute the last timestamp's difference with the current timestamp in minutes. I'm wondering if this can be optimized further for production. ...