Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange
The results are in! See what nearly 90,000 developers picked as their most loved, dreaded, and desired coding languages and more in the 2019 Developer Survey.

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.

4
votes
1answer
46 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
54 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
35 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
57 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
35 views
1
vote
0answers
23 views

Determining daylight-saving time in Central European Time

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 string like '31.12.2019', we're ...
3
votes
2answers
31 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
25 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
63 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. ...
2
votes
1answer
35 views

Get the suffix for the date string

Sometimes I have the date as part of the file name. And then when Emacs autocompletes the file name, it puts the part of the date. In these situations I have to write the rest of the date manually. ...
4
votes
2answers
752 views

Fake utcnow for the pytest

I want to create a pytest with a fake utcnow, but also I need to preserve the functionality of all other datetime methods. ...
0
votes
1answer
41 views

JavaScript - Difference between two dates in days or less [closed]

I have 2 dates that I would like to have the difference between them in days and if less than a one day simply show "less than a day". ...
0
votes
1answer
130 views

XMLGregorianCalendar to LocalDateTime

From some generated code I get a javax.xml.datatype.XMLGregorianCalendar and I want to convert it to a LocalDateTime without any ...
7
votes
5answers
604 views

Find the next monthly expiration date

I have an agreement with a customer. When the agreement ends, the customer needs to pay. The amount which the customer needs to pay increases for each month that has passed since the agreement was ...
4
votes
2answers
220 views
1
vote
1answer
57 views

Parsing a string to a java LocalTime

I have a method that can take in a time string in one of the following formats: HHmmss - e.g. 073055 = 07:30:55 ...
3
votes
1answer
61 views

Formatting time delta

Quite often, I find myself measuring how long some part of my code takes to complete. I normally do that by storing current time using time.time() and then ...
2
votes
0answers
33 views

A portable cross platform C++17 method to retrieve the current date and time

I am working on a utility function to get the current date and time. My objective is to do this in a generic and portable way. I would like to stay way from platform specific code to allow the ...
10
votes
2answers
137 views

Javascript cron-to-human-readable translator

I'm developing a webpage displaying the scheduled pipelines from all projects of a GitLab instance. The scheduled time is expressed using CRON expressions, i.e. five digits as follows: Because not ...
4
votes
1answer
202 views

Algorithm to find the number of years, months, days, etc between two dates

I've been working on this one for a while. Took me a while to figure out all the logic rules for dates and months. The goal of this method is to return the number of years, months, days, hours, ...
2
votes
0answers
57 views

PHP project with Google Calendar API

I'm playing with a simple (for now) project in PHP with Google Calendar API. I have posted the code here in order to improve my programming style about whatever you think it's worth suggesting. Thank ...
1
vote
2answers
35 views

Generate n appointments in the next m months

I work with an API where I need to write code to generate n appointment dates in the coming m months (from today). For the purpose, I write a Random date generator class provided. One condition is I ...
2
votes
1answer
53 views

Calendar holidays to XML

We are writing program which makes XML file which is a calendar with all free days in Poland (Saturdays, Sundays, and all hollidays). We tried to write this code as readable as possible so probably no ...
0
votes
0answers
29 views

Laravel working with dynamic start and end dates to grab some data

So, to start off, the below code does work, but it feels like a newbie solution to me, and if I ever need to come back to this code, I will have no idea what I was thinking. I have a table called <...
2
votes
0answers
28 views

Get local datetime from UTC time

One of the app is inserting date in UTC format (column CreateDate). When reporting from this table, I used a difference in hours between the inbuilt ...
1
vote
3answers
53 views

Change state depending on holidays, weekends or hour of day

I'm writing a script that's changing the background color depending on hour of day, if it is a weekend or if it is a Swedish holiday. I have a functional script and as I want to improve my programming ...
5
votes
1answer
39 views

Scheduled file sorting with Ruby

I have a script running as an hourly cron job. It finds all screenshots on the Desktop and moves them to directories sorted by year/month/day. On MacOS, screenshots are automatically saved to the ...
1
vote
0answers
57 views

Retrieving date and time from Datepicker and Timepicker and then converting it to milliseconds

I currently have an Android Activity that allows the users to select the startDate, endDate, ...
0
votes
1answer
45 views

Pure JS countdown clock not converting millisecond time correctly [closed]

I have a semisimple pure js countdown clock that I am having trouble converting the millisecond time correctly. Here is a working Plunker (besides the date counter) It Should only be 38 days instead ...
2
votes
2answers
94 views

Calculator to add time intervals

I have written a little program that calculates the time by given strings. A time string in the context of this program consists of a number and a following letter that can be s, m, h, or d. You can ...
2
votes
0answers
132 views

Event Calendar in JS, CSS, and HTML

I repeated a lot of code here and I'm trying to use more ES6 but I'm not sure where I should have used it in my code. I'd appreciate any input on where I could improve. GitHub ...
3
votes
1answer
31 views

Iterate between dates and INSERT values in a performant way

I have created a query that populates a datapoint with random values. The logic is simple: Iterate between the START and END dates and INSERT random values. I want from this query to be very ...
1
vote
1answer
78 views

Parsing displayed month/year for calendar

I have a 6 x 7 grid for a calendar = 42 DateTimes. I'm trying to display the displayed month/year at the top of the calendar. If there are 3 months displayed, I ...
2
votes
1answer
42 views

Extracting and reformatting dates from text

The task is find by pattern d--m--y---- all occurrences in text, reformat it to yyyy:mm:dd and print it separately from initial text. Actually I done all except formatting. And even in my written ...
1
vote
1answer
48 views

Calculate the number of days passed from a given year

I have this code for calculating the number of days passed from a given year: ...
2
votes
2answers
70 views

Python date formatter

I'd like to find the best way to format date to YYYY, YYYYMM or YYYYMMDD. Here is what I've got so far: ...
2
votes
3answers
77 views

Printing a monthly calendar on console

This is an implementation of mine to an exercise found in the book Core Java SE 9 for the Impatient. Goal is basically to print a monthly calendar by accepting month and year information from the user....
1
vote
1answer
73 views

Renting vs. owning comparison calculation

I have working code that compares rental prices and owning costs, given some parameters. It works, but it surely does not look good. I hadn't worked with time-series before and I wonder how I could ...
3
votes
1answer
562 views

Count days from overlapping date periods with Carbon

I had to calculate the total number of days from overlapping date ranges (coming from MySQL in my case) excluding weekends and here is a working version of what I did. I am looking for a cleaner ...
3
votes
2answers
338 views

Reformatting a date from YYYY-MM-DD to MM/DD/YYYY

In this small bit of JavaScript, a date is passed in as YYYY-MM-DD. It's formatted like this to be passed to the backend system. On the front end, we need to ...
-2
votes
3answers
74 views

Translate a day in year to month and day 2nd method

Take an integer representing a day of the year and translate it to a string consisting of the month followed by day of the month. For example, Day 32 would be February 1. I've already submitted my ...
1
vote
1answer
73 views

Contest Solution: Al Gore Rhythm

The Problem After his brush with the Justice Department over fundraising with Buddhist monks, the Vice President devised a plan to ensure that such activities are carried out in a more discrete ...
1
vote
1answer
83 views

Translate a day in year to month and day

Take an integer representing a day of the year and translate it to a string consisting of the month followed by day of the month. For example, Day 32 would be February 1. This is what I came up with. ...
6
votes
3answers
3k views

Checking if two time intervals overlap

I have two time intervals i1 and i2, each defined by two values, begin and ...
2
votes
3answers
62 views

Display date and/or time

The code below takes an input and based on the input gives out a time, date or both. Please will you review me for this and tell me how I can improve this? By the way, I only started learning python. ...
4
votes
5answers
99 views

Leap year determination using guard clause

I have a function to check the leap year as follows ...
2
votes
1answer
102 views

Java function to format seconds as minutes, hours, days

Anyone know how I write this code shorter, with modulos maybe? I also want to add weeks and years do this code, but it kind of got too long for that. Maybe there is some smart algoritm? Something in a ...
4
votes
2answers
162 views

Sleep until specified time

It's sometimes useful to pause until a specified time (but inconvenient to use at or the like), so I wrote a tiny script to wait until a user-specified time point ...
4
votes
1answer
54 views

Subtable timestamps in python pandas

I have a dataframe like: ...