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
12 votes
1 answer
1k views

Responsive/adaptive website code

I have all these functions that work together to create functionality on a page. Is the structure of these functions OK? Can I do anything to speed this up or make my code better? I'm not exactly ...
HandiworkNYC.com's user avatar
17 votes
2 answers
5k views

It's Friday! - Zeller's Congruence Revisited

A couple of date-related questions have come up recently, and on both occasions I have been taken back to my 'early' days where one of my first forays in to programming involved implementing Zeller's ...
rolfl's user avatar
  • 97.3k
29 votes
4 answers
7k views

Is it Friday yet?

This is the first program that I have written in my C++ saga that I actually think is useful. The description for this assignment is kinda long and mundane though: Write a program that inputs a ...
syb0rg's user avatar
  • 21.8k
9 votes
2 answers
331 views

Generating fiscal calendar dates

I need to generate a T-SQL script for loading data into this table: ...
Mathieu Guindon's user avatar
8 votes
1 answer
1k views

Multi-function clock GUI

I was sitting in my bedroom, looking at my Powers of 2 clock sitting next to my radio, under my analog clock on the wall, and wondered to myself: "Why have all these different clocks when I can have ...
Eric Roch's user avatar
  • 387
3 votes
1 answer
80 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 ...
chux - Reinstate Monica's user avatar
2 votes
1 answer
206 views

Date only limited function class

Per the title date only class (or struct?). .NET does not offer a date only data type. I get there is time zone dynamic but then you have daylight-savings that can still kill you. I do document ...
paparazzo's user avatar
  • 5,946
2 votes
1 answer
187 views

Date validation in Java - take two

I read through and implemented the advice I received yesterday. I would, once again, really like some input on how this can be improved. e.g. encapsulation, interfaces, abstract classes etc.. Right ...
Nilzone-'s user avatar
  • 1,416
2 votes
1 answer
281 views

Date validation in Java

I'm learning Java, and would really appreciate any tips on how to improve this code. It's just a simple date validation class. ...
Nilzone-'s user avatar
  • 1,416
1 vote
1 answer
788 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. ...
dino2018's user avatar
24 votes
4 answers
32k views

Simple Age Calculator

I have written an age calculator that takes a birthDate as input. I'd like a general review of this. I'm especially concerned about the ...
Commodent's user avatar
  • 425
20 votes
5 answers
24k views

Calculate future date based on business days

I've written a program for calculating the future date after certain number of business days. ...
Mohammad Faisal's user avatar
20 votes
3 answers
7k views

Find easter on any given year

To find the days off for our custom accounting software there is this method used to find when is Easter in any given year. ...
Matt's user avatar
  • 209
16 votes
1 answer
57k views

Alternative to setInterval and setTimeout

JavaScript's setTimeout() and setInterval() are evil and not precise: Both functions have a delay of a varying quantity of ...
cocco's user avatar
  • 303
16 votes
3 answers
531 views

Type-safe Date class with total encapsulation

I want to teach about "encapsulation" and chose Date with Year, Month and ...
towi's user avatar
  • 608
14 votes
3 answers
17k views

Verify if meeting datetime ranges overlap in an IEnumerable list of meetings

I have an assignment where I need to find out if any of the meetings in a list of meeting class object have overlapping datetime ranges. What I have so far is this: ...
Dave Adler's user avatar
13 votes
5 answers
11k views

Cleaning up date strings in Python

Working from a CSV of about 14.000 lines, I need to match dates in the CSV against some API. I'm reading the CSV using Pandas (for various other reasons). Most often, the date is just a year, i.e. an ...
RolfBly's user avatar
  • 827
12 votes
2 answers
361 views

Prorated refund calculator

I wrote this little piece of script for my workplace (insurance, etc.) to help our admins, as a light and simple file I can just email to my colleagues. The purpose of it is to calculate a prorated ...
Phrancis's user avatar
  • 20.4k
11 votes
4 answers
51k views

Converting the DateTime to and from Unix epoch times

I'm currently working on a thing I needed this feature for. Essentially, these are two methods to convert DateTime objects to and from the Unix epoch time (two ...
Der Kommissar's user avatar
10 votes
1 answer
1k views

Generate iCalendar .ics files with events for astrological aspects

I'm relatively new to Python, coming from a deep C++ background. I'm mostly looking for feedback on how to make my code more idiomatic/pythonic, but I would welcome and appreciate any and all other ...
feuGene's user avatar
  • 363
10 votes
5 answers
11k views

Function for checking leap years

As part of one of my AP Computer Science labs, I was required to write a function to determine whether a year was a leap year or not. Included as comments are a few reasons why I did things, as well ...
Pip's user avatar
  • 354
9 votes
2 answers
78k views

Converting seconds to hours, minutes and seconds

The following question was taken from Absolute Java 5th ed. by Walter Savitch: Write a program that outputs the number of hours, minutes, and seconds that corresponds to 50,391 total seconds. The ...
Oompa Loompa's user avatar
8 votes
2 answers
1k views

Digital clock with many functions

I made a digital clock with the use of an RTC (DS3231) and an LCD (16x2). Current functions: Display time Display date (different formats) Display temperature (Celsius and Fahrenheit) Display day ...
Sebastiaan Speck's user avatar
8 votes
3 answers
6k views

Calculate a month later than current month (without rolling over to next month)

I needed a script for working out billing dates over a period of time. The date should be the same day every month however if the billing date starts on a date that doesn't exist in another month, ...
Keir Lavelle's user avatar
8 votes
3 answers
5k views

Format a timespan with up to two fields

I'm looking to achieve a time format that looks like this: 2d 4h remaining; or 1h 36m remaining; or 35s remaining, etc. So that it only displays the two largest values of time (this is how Clash of ...
Essential's user avatar
  • 255
7 votes
3 answers
266 views

Enumerating new articles whose publication start date has passed

(cn.PublishEnd == null || cn.PublishEnd < DateTime.Now) vs (cn.PublishEnd ?? DateTime.MinValue < DateTime.Now) Which ...
bevacqua's user avatar
  • 357
7 votes
6 answers
636 views

Conditionals for time specific data

This is a fun piece. I have this block of code here: ...
AndyRoid's user avatar
  • 293
7 votes
2 answers
217 views

Scraping lunar/solar eclipse data with BeautifulSoup

I created a script to scrape this website and gather the eclipse data (date, type, and location): ...
user avatar
7 votes
2 answers
80 views

Printing the days of the week for every day this year

@chux pointed out that my attempted solution contained several problems. Since I screwed that up so badly, I figure that I should put my revised solution up for review. ...
200_success's user avatar
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
6 votes
1 answer
1k views

Dict of names and birth dates which prints with age at birthday of current year

As a beginner (Learn Python the Hard Way), I've set myself this exercise with classes and it works but looks very inelegant to me. I'm trying to write classes which could be re-used in other code. I'...
j-o's user avatar
  • 137
6 votes
2 answers
2k views

Calculating months elapsed since a given date

I am using traceview and DDMS to analyse my operation. The following is my traceview as displayed in DDMS: According to the above, the LoaderClass.months() ...
Junaid's user avatar
  • 217
6 votes
5 answers
26k views

Date class in C++

This is a Date class in C++. I didn't use C++ strings because I'm not sure if I'm allowed to. It seems to work fine, but I'm wondering if there are any errors I ...
user avatar
6 votes
3 answers
758 views

Displaying TimeSpan as largest interval (with units)

The following method is used in a call center application to display an approximation of remaining time. The call center telephone operator would inform the caller that they could perform their ...
László Koller's user avatar
6 votes
3 answers
208 views

Weekday+day validation

The string I'd like to check is something like "abcSun24def". If any valid "xxxyy" (xxx = weekday and yy = day) is found, return the position inside the string. If "xxxyy" is not found, return -1. ...
geohei's user avatar
  • 245
6 votes
2 answers
531 views

Using an API to obtain JSON data and get the date string and determine if data is stale

This is a nagios check that will use an API URL, get JSON data, flatten the data into a usable perl hash, and ultimately obtain a date string. Once the date is obtained, it should recognize the ...
japtain.cack's user avatar
6 votes
2 answers
87 views

Conditionals for time specific data (SQL style)

I was inspired by this question from @AndyRoid to try and come up with some fast and accurate datetime calculations that didn't involve complex if/...
Phrancis's user avatar
  • 20.4k
5 votes
1 answer
8k views

Parsing and evaluating cron expression

I wasn't happy with my last attempt to parse a cron expression so I simplified it and now I use regex instead. I'd like you to take a look at this solution whether I'm doing something terribly wrong. ...
t3chb0t's user avatar
  • 44.2k
5 votes
2 answers
147 views

Find Date in Range

I have a spreadsheet where I control my shift hours. In such spreadsheet I input the date, the start time, time left for lunch, time back to work, end time and sometimes the overtime. After that I ...
Victor Moraes's user avatar
5 votes
3 answers
291 views

Transferring data for a given month from one sheet to another

I have dollar amounts sorted by month that I want to transfer from sheet entry to sheet actuals. I only want to do it for a ...
findwindow's user avatar
5 votes
1 answer
259 views

Inefficient Stopwatch

I have just finished a simple GUI stopwatch, but some of its code looks like it needs replacing. This is the code: Clock class (extends Thread): ...
TheCoffeeCup's user avatar
  • 9,454
4 votes
1 answer
236 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 ...
Rick Davin's user avatar
  • 6,267
4 votes
1 answer
575 views

Classification of Date/Time/DateTime

I'd like to share a methodology I've been using when faced with a classification problem. This particular example is designed to classify time data as Date/Time/DateTime. Though I believe it could ...
James Schinner's user avatar
4 votes
5 answers
14k views

Calculate next working day

I have tried to tackle this question as follows: ...
Perfect's user avatar
  • 41
4 votes
1 answer
97 views

Average interval between dates with random blanks

I have a spreadsheet with order date data: I need to find the average interval in days between each order date. I have to both find a way to get past the blank cells in the row, and also take into ...
Chrismas007's user avatar
4 votes
1 answer
2k views

Using swing and creating JPanel

I watched bunch of videos about swing and GUI in general and created my first component (correct me if it is not one). JPanel class: ...
Townsheriff's user avatar
4 votes
1 answer
2k views

New year countdown

Here's some code I wrote quickly to get a nice millisecond countdown going. It displays the number of milliseconds until the new year in whatever timezone is next to be in 2015 are in in huge font, ...
bjb568's user avatar
  • 659
4 votes
1 answer
1k views

Optimize MySQL double select inside for-loop

I want to get the number if items with state 4 and 1 from my database for each day between a certain date. Is there a smarter ...
Rikard's user avatar
  • 163
3 votes
2 answers
80 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.2k
3 votes
1 answer
1k 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 ...
Andy's user avatar
  • 43