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,046
questions
2
votes
0
answers
90
views
Time Schedule Intersection version 2
Time schedule intersection
in my original question I gave an answer which has \$O(n^2)\$ complexity.
Here is the new version of the same problem.
I'm trying to get to O(N+K). please review the code ...
1
vote
1
answer
621
views
Converting Date object in CoffeeScript to string (with a weird format)
I'm trying to convert a Date object into a weird format, like so:
03/30/2017 11:37:14:082 -0500
The issue that really trips me up is the timezone offset. There's ...
4
votes
1
answer
759
views
Convert FoxPro/dBase DATETIME field to Win32 SYSTEMTIME struct
I'm trying to write a complete driver for Visual FoxPro's DBF format for Win32. I found that the way that fields of the DATETIME type are stored in dBase files is ...
3
votes
1
answer
2k
views
Generate next available filename based on current date
I have a bit of code that I would like your collective opinions on. Currently, my working code has two return statements. I'm not sure how I feel about having multiple points of exit, however, the ...
3
votes
1
answer
486
views
Select items between two dates that are available
I wrote this MySQL query, but I feel it could be better. I had to get all clients between today and 14 days' time, that have at least one day "free". I have a SQL Fiddle, and there you can see how my ...
4
votes
1
answer
154
views
Handling two datepickers in a form with angularjs
Here's I am using simple form with angularjs. Everything works fine. I am having watchgroup for EndDateFrom & EndDateTo datepickers. When it's defined I am logging the value to console. I am ...
2
votes
1
answer
2k
views
Pulling time and date from the internet
I'm pulling the time and date from the internet because when the user turns the Raspberry Pi off, it loses its date and time settings and unfortunately
Windows 10 IoT is very slow to correct it.
I ...
16
votes
5
answers
972
views
timeleft utility
This utility tells you how much time is left until the time you set before.
Setting time:
> timeleft set '2017/04/25;15:00:00'
Using utility:
...
5
votes
3
answers
233
views
Print the name of day
How can I improve this code? It takes a number in the range of [1,7] and prints its corresponding day.
...
3
votes
1
answer
342
views
Set time zone from cookie
Is the set_cookie variable the correct way to signal that the cookie should be set? It does not seems pythonic to me:
...
5
votes
1
answer
15k
views
Calculate working days and excluding specific dates (Holidays)
I read some questions/answers related to functions in C# to calculate the working days; some use an extended code to achieve that.
I have a data table with more than 50,000 rows and I required an ...
-2
votes
1
answer
498
views
Calculate the number of days between two dates
This program uses user-input variables to calculate the iDays a person has been alive for (or the iDays between two input dates),...
4
votes
3
answers
2k
views
Leap year check in Haskell, using pattern matching or bind operator
One of the first Haskell puzzles on http://exercism.io/ is to implement a leap year check. I've done this twice.
Using pattern matching:
...
0
votes
1
answer
65
views
Calculate time difference when using time only fields [closed]
Most of the time I used datetime fields, but for this project it is a requirement to use time fields. The problem is calculations with 2 times not on the same date.
I.E.:
23:00 to 03:00 is 4 hours.
...
1
vote
1
answer
57
views
Class to represent a mutable date and time
What would be the best way to refactor this class - if any at all? I'm using this class to get the current date and time and also to modify this date by being able to change its date and time. I ...
1
vote
2
answers
173
views
Output CSS class based on day-of-the-week match
The goal is to loop through an array of days-of-the-week (array values are stored as strings, eg: 'Mon, Tues, Weds', etc) and output some HTML when today's day is encountered.
The file is a CMS's ....
5
votes
1
answer
11k
views
Simple elapsed time counter
I've written a simple JavaScript function based off some existing code that takes a specific UNIX time string (in the snippet: 1491685200). It shows an alert if the ...
5
votes
1
answer
3k
views
Python library for calculating next and previous time of the cron-like scheduled task
I needed a task system that would let me define a cron-like rule in the database, and be able to find the next and the previous time when the task was and is supposed to happen.
I am running a web ...
2
votes
1
answer
75
views
Convert ISO 8601 week to American-formatted date
Requirements:
Implement a function that, given a standard date and an indicator
whether or not the output should be in american standard (weeks start
on sundays, the first week of the year is the ...
4
votes
1
answer
8k
views
Finding consecutive days in an array of dates
The problem:
How to get the largest number of consecutive days from an array of unknown number of Date objects, by taking into account days only like 4th of April, 5th of April and so on.
Example ...
2
votes
2
answers
102
views
Writing a date checker in C
I'm currently working on writing a date checker function in C and wondering how it can be improved upon.
Q: Write a function that is passed a month, day, and year and will
determine if that date ...
1
vote
2
answers
2k
views
Program that reads a string from the keyboard and tests whether it contains a valid date
I know this task could be done in more practical ways, but the professor only want us to solve it with the "if" statement. I tested and it meets the condition for each task, but I still feel this code ...
4
votes
2
answers
67
views
Create and open a file to take lecture notes depending on day and time
I am just wondering what, if any, more elegant ways might exist to write a script to accomplish the task that the script below accomplishes. The script works, so I don't need it to be debugged, but I ...
2
votes
1
answer
207
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
1
answer
7k
views
Converting UTC time to date in d3
I intend to convert strings that are UTC timestamps into a date format, say day + date number (e.g. 'Mon 27'). My current solution is:
Parse the UTC timestamp into a date object using ...
4
votes
2
answers
2k
views
Matching a time interval using regex
What I needed to do was check whether a given string matches a certain pattern. The pattern is this:
00:00:00,000 --> 00:00:00,000
Things to keep in mind:
...
5
votes
1
answer
615
views
Airport scheduler
This is the problem:
Airport
Pretend we are operating a small airport with a single runway. We
need to develop a data structure to help scheduling airplanes to take
off and land from this ...
5
votes
1
answer
2k
views
Simple calendar in PHP
I made a simple calendar in PHP 7.0, could anyone help with simplification? Any advice appreciated. It works, but I totally believe it can be improved. I am a beginner.
...
3
votes
2
answers
502
views
Article date extractor
I am quite new to Rust and this is my first library written in it. It's an article date extractor heavily inspired by the original Python library as well as its Haskell port.
It is fairly small and ...
5
votes
1
answer
316
views
Difference between API time and server time
I'm using the openweathermap API to get weather forecast data. I want to make sure that the forecast values are at minimum 2 hours in the future. The API is providing the forecast in 3 hour steps, so ...
6
votes
1
answer
113
views
Function that returns index of Forex candle according opening hours (weekly session)
The output of the function is as desired. When Forex opens at Sunday, first candle is annotated with 1 and the number increments with every new candle, till weekend, when the imaginary counter is ...
8
votes
1
answer
3k
views
Make To and From date range picker using jQuery UI
I implemented date range picker logic using the jQUery UI datepicker component:
...
4
votes
4
answers
15k
views
Specifying the Kind on DateTime
I've got a system and every object in my system has a base class with property: DateTime DateCreated
In the constructor for the base class I set the ...
7
votes
4
answers
350
views
Formatting date depending on current date
I have two screens where I show a message creation time and date. Initially, there was only one screen and I should always show time and show date differently depending on difference between today and ...
6
votes
1
answer
122
views
Calculating parking and charging statistics for a car-sharing service
I am looking for help in designing my code more efficiently and also in keeping the slope of my personal learning curve steep:
For a research project I have per car data from two different car ...
5
votes
3
answers
5k
views
Implementing a week schedule class in C#
Requirements
A week schedule class
.NET framework has DateTime struct, but I want a general week schedule class that involves day of week instead of date. For example, a shop has open hours from 9:...
12
votes
3
answers
33k
views
Show time in format yyyy-MM-ddThh:mm:ss.SSS
My requirement is to convert a time (long) to a String with this date format:
yyyy-MM-ddThh:mm:ss.SSS
For instance: 2017-03-07T03:52:31.298
My implementation:
...
1
vote
0
answers
839
views
getDayOfTheWeek function, without using built-in date libraries
I have an assignment to create a method to retrieve the proper day of the week for any given date, without using the Java calendar. After countless hours of trying to implement the algorithm in the ...
2
votes
2
answers
884
views
Get first DateTime by given weekdays and a starttime
At work there is an input-system where customers are able to specify weekdays and a starting time for an event. The weekdays are integers in the range from 1 (Monday) to 7 (Sunday).
After the customer ...
10
votes
2
answers
31k
views
Converting std::chrono::time_point to/from std::string
Consider these functions that allow to convert std::chrono::time_point to/from std::string with a predefined date-time format.
<...
7
votes
1
answer
261
views
Coalesce consecutive failures in a DataFrame of hourly sensor readings
I have a PANDAS DataFrame that contains sensor data that is recorded every hour (sample included below). It is important to note that every hour is not necessarily in the dataframe, as sometimes the ...
1
vote
1
answer
308
views
Round fractional seconds of MySQL Time
I've written a method to round a MySQL Time to two decimal places. Here's some examples:
...
3
votes
4
answers
260
views
JavaScript clock
I am trying to build a clock. You can see the working code here. However, I feel like I can do much better in the JavaScript code.
...
3
votes
3
answers
313
views
Function to check if a date is correct
I have a method that checks if a date is correct or not, which returns a boolean if it is or not. In the method, I first check the format, then the date by using the function ...
5
votes
1
answer
3k
views
Optimize calculation for the amount of time between when a value changes in Pandas
I have some sensor data that contains timestamps from when a machine is turned on and an indicator variable showing whether or not the machine is actively running. The data is mostly recorded every ...
1
vote
0
answers
2k
views
C# Regex to match UTC dates
Made the following regex strings to match for typical UTC dates. I'd appreciate it if you guys can let me know if it seems fine and not too lengthy.
...
3
votes
1
answer
3k
views
Array of date by each week
I have two dates, example :
date1 = "4-02-2017".to_date
date2 = "4-02-2017".to_date + 29
I try to get array of date by each week with this :
...
2
votes
2
answers
120
views
Simple timer checking class
This is a simple class that runs a timer every 10 seconds to update the title with some information like how long the application has been up, depending on the datetime that is set in another class ...
2
votes
2
answers
10k
views
Rounding a time to its lowest quarter-hour
I calculate the lowest quarter-hour using the following code:
...
0
votes
2
answers
20k
views
Interpret YYYYMMDD as the nth day of the year [closed]
I am provided a bunch of dates in the format (YYYYMMDD) such as:
date='20170503'
My goal is to convert that date into the ...