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.
60
questions
12
votes
1answer
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 ...
17
votes
2answers
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 ...
28
votes
4answers
6k 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 ...
9
votes
2answers
295 views
Generating fiscal calendar dates
I need to generate a T-SQL script for loading data into this table:
...
8
votes
1answer
973 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 ...
2
votes
1answer
166 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 ...
2
votes
1answer
240 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.
...
2
votes
1answer
177 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 ...
1
vote
0answers
91 views
Watch that uses the abstract factory design pattern
I have wrote code for a Watch that utilizes the abstract design pattern and would like to get some feedback on the code, be as harsh as you can. Also, I would like ...
1
vote
1answer
127 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. ...
17
votes
1answer
41k 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 ...
24
votes
4answers
31k 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 ...
20
votes
5answers
21k views
Calculate future date based on business days
I've written a program for calculating the future date after certain number of business days.
...
9
votes
2answers
77k 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 ...
12
votes
3answers
12k 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:
...
13
votes
5answers
7k 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 ...
9
votes
4answers
46k 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 ...
6
votes
1answer
3k 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.
...
2
votes
1answer
3k views
Approximating/Sorting groups of dates into buckets
I'm working on a directed study project with a professor of mine helping him build out a Django based website. The website is a historical account of the people, events, projects, and organization in ...
19
votes
3answers
5k 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.
...
12
votes
2answers
311 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 ...
10
votes
5answers
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 ...
8
votes
3answers
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 ...
6
votes
5answers
18k 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 ...
6
votes
3answers
169 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.
...
6
votes
2answers
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() ...
5
votes
2answers
128 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 ...
3
votes
1answer
192 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 ...
2
votes
1answer
7k views
Milliseconds to Time string & Time string to Milliseconds
Fast Time conversion
I'm trying to write a very fast time-to-string and string-to-time function.
I noticed that on low CPU mobile devices this function has, even if minimal, impact on the ...
1
vote
1answer
1k views
Track execution time using std::chrono facilities and print the execution time in a comprehensible way
The class below will be used to track the execution time of various operations. There is no need to dip into C libraries to get formatted output then.
Output would be something like this:
10 ...
16
votes
3answers
522 views
Type-safe Date class with total encapsulation
I want to teach about "encapsulation" and chose Date with Year, Month and ...
10
votes
1answer
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 ...
8
votes
3answers
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, ...
8
votes
2answers
527 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 ...
7
votes
3answers
258 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 ...
7
votes
2answers
173 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):
...
7
votes
6answers
477 views
7
votes
2answers
70 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.
...
6
votes
2answers
472 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 ...
6
votes
1answer
947 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'...
6
votes
2answers
77 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/...
5
votes
1answer
238 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):
...
5
votes
3answers
283 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 ...
5
votes
3answers
593 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 ...
5
votes
1answer
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 ...
4
votes
1answer
90 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
1answer
93 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 ...
4
votes
1answer
1k 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, ...
4
votes
1answer
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:
...
4
votes
1answer
430 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 ...