Stack Exchange Network

Stack Exchange network consists of 174 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

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.

1
vote
3answers
39 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
30 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
32 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
22 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
90 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
46 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 ...
2
votes
1answer
28 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
votes
0answers
14 views

Converting end user local to UTC and back

I'm wondering if I'm doing this correctly or if I went too far or not far enough. I have a scheduling/POS system in which each location has its own data. Each location will report on its own data. ...
1
vote
1answer
76 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
39 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
47 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
54 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
2answers
56 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
60 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 ...
2
votes
1answer
162 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 ...
2
votes
2answers
103 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
73 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
66 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
78 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
881 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
55 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
96 views

Leap year determination using guard clause

I have a function to check the leap year as follows ...
2
votes
1answer
72 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 ...
3
votes
2answers
114 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
48 views

Subtable timestamps in python pandas

I have a dataframe like: ...
2
votes
1answer
63 views

Crontab datetime field pattern parser in Rust

@angus on Unix.SE implemented a tool in C to list upcoming cron jobs in response to a question. I've re-implemented the basic functionality (showing only the next cron job) in Rust, using ...
2
votes
2answers
80 views

React clock component

I'm new to React.js and this code came from 30 Days of React - Day 7. However the given code example wasn't working so I rewrote it myself. My biggest issue here is how to make the component work ...
4
votes
1answer
51 views

Format seconds into the two biggest units of time

I wrote a function to convert seconds into the two biggest units of time and format it into a string. What I mean is that e.g. 134 second would be 02m14s and 3665 ...
2
votes
2answers
55 views

Leap Year game in Java

I created just for practice this leapyear script. What do you think about it? How can I make it more efficient? ...
2
votes
1answer
51 views

Simple Duration calculator using es6 class syntax

I've written a simple script that calculates the distance between two points in time and returns the duration. Example: Start - 11:00, End - 11:45, Duration - 0.75 I wanted to make use of ES6 ...
11
votes
1answer
85 views

CodeVita challenge: forming the latest valid datetime in a year using some given digits

After answering someone's Code Review question, I decided to tackle a sequel: Given an input consisting of 12 non-decreasing single digits separated by commas, form the latest valid date time in a ...
2
votes
2answers
58 views

Parsing date strings, inferring the year such that the date is not in the future

I got this program that I am working on and in it, I got a section that has a try statement and two error except statements. ...
18
votes
8answers
5k views

Program to check if a date is valid or not

I am a novice programmer and am currently learning Python programming by myself through a book. I stumbled upon a question in a chapter and it took me 2 days to figure out a solution for it. Although, ...
2
votes
2answers
80 views

Listing files whose names match a pattern with a date

My directory folderMarket has lots of files with the same name but are tagged with a date string at the end. The date tag can be formatted differently, e.g. "2018-...
7
votes
2answers
386 views

Code Vita: Form the maximum possible time in the HH:MM:SS format using any six of nine given single digits

Problem Description The objective is to form the maximum possible time in the HH:MM:SS format using any six of nine given single digits (not necessarily distinct) Given a set of nine ...
5
votes
3answers
119 views

Displaying the date in MM/DD/YY format

I spent about an hour and a half attempting to complete a problem from W3Resource. Here is what I came up with, which works. How can I shorten it? ...
12
votes
5answers
3k 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 ...
2
votes
2answers
72 views

Random binary digit generation and file I/O

I've recently made a program which generates a (pseudo) random binary digit (1,0) which is tied to a specific subject to learn for every day of the week. The program generates the digits the first ...
3
votes
1answer
67 views

JavaScript flipping clock

Here are two simple classes - Digit class maintains digit behaviour - primarily flipping animations, and Clock class handles everything that is related to time data. I'm going to use this code for ...
3
votes
1answer
37 views

Stored procedure for sending emails at specified times after license expiration

I need to send email notifications for expired licenses: One Day Before/After Expiration Two Days Before/After Expiration Three Days Before/After Expiration One Week Before/After Expiration Two Weeks ...
1
vote
1answer
59 views

Fuzzy Humanize date using Moment.js for datatable searching

In my JS project, I am using datatable plugin to show data where I have a date column which users can filter/search. In order to help users to search using a logical string such as ...
1
vote
2answers
72 views

Convert minute to time for display

I am new to javaScript, I just coded a method where I can convert a minute to a time in hh:mm AP/PM. I was then displaying the time in a table. I was wondering if there is a better approach to this? ...
4
votes
1answer
101 views

Age in hours calculator

I've written a small script, which calculates hours since the birth. I ask use about how old they are in years, months and day. I show them approximately how many hours they have lived. Below is the ...
3
votes
1answer
526 views

Convert a string in time format to minutes

I am new to C#. I just created a method where I can convert a string with the format HH:MM AM/PM to minutes. I was wondering if there is a better or more effective way to achieve the same result. <...
2
votes
2answers
76 views

Summing payments by year using Java Streams

I'm using 1.8.0_162 version of Java and here is my task about stream framework ...
6
votes
2answers
1k views

Calendar for any given month/year

This is one of my first C++ training project where I created the console application which displays the calendar of any given month. I observed how offset of days (empty places on the calendar) ...
1
vote
1answer
63 views

Get start and end dates and strings

I have a method to get the time parameter, is this code neat, can the return parameter use other data structures? ...
9
votes
6answers
2k views

Loop months between a time span yyyy-mm and yyyy-mm

I'm trying to come up with a more elegant solution for a loop in months that I wrote long time ago in C# 1.1 I use a helper class Month but I'd prefer to get rid of it and make the code shorter and ...
5
votes
1answer
100 views

Calculate the intersections of opening hours

I have a solution but it feels bloated and unclean. How can I clean it up? The second for loop especially does not feel right. I'm trying to calculate the opening ...