Is it time to ditch daylight saving time - am I managing my dates and times correctly?

Currently, I am in the process of working on a PHP/mySQL web application where dates are stored as unix timestamps in columns that are UNSIGNED INT(10). When it comes to displaying these dates in the web view, we utilize moment.js to parse the numbers.

One of my colleagues expressed concerns about this method and instead suggested storing dates as "YYYY-MM-DD hh:mm:ss" VARCHARs. However, we have not encountered any issues with our current approach so far.

I recently came across news about the European Union's plans to abolish daylight saving time. I'm wondering if this change will have any impact on my web application considering how I am currently storing dates?

Answer №1

Here are a few key points to consider:

  • Instead of storing dates and times as integers or varchars, MySQL provides standard data types like DATE, DATETIME, and TIMESTAMP. You can learn more about these types in the MySQL documentation.

  • The choice of how to store dates and times should be based on the specific context. While some suggest always using UTC, it's important to consider the meaning behind the date and time being stored. For example:

    • A Unix Timestamp is tied to UTC and is ideal for representing past or present events. In MySQL, the TIMESTAMP type aligns well with this concept.

    • If you're storing future event times, local date and time become more significant. This would typically be stored in a DATETIME field, along with a corresponding time zone identifier (e.g., America/New_York). When dealing with multiple time zones, understanding DST requires considering the rules associated with that specific time zone.

    • For whole dates like birthdays or specific calendar days, utilizing the DATE type without a time component is appropriate. In these cases, DST does not play a significant role beyond determining which day a particular point in time falls within.

  • The question of EU DST abolition and its impact on time zone data implementation is complex. Further insights on this matter can be found in this helpful explanation regarding the IANA time zone database and the current situation in the EU.

Answer №2

In my opinion, it shouldn't make a difference. Personally, I store dates as UNIX timestamps too, and if you're using a method like:

getSecondsSinceEpoch = ((date) => Math.floor(date.getTime()/1000));

(or any other function that utilizes Date.prototype.getTime()), then you are storing a universal date that is independent of timezones. This can be beneficial because regardless of the user's timezone when they log in, you will not be returning values based on where they were previously located. The same principle applies when Daylight Savings Time alters the clock in their region (or remains constant after being abolished).

To display the correct human-readable date string for the user's specific location, Javascript uses a timezoneOffset, which determines how many time zones away the browser is from London at that moment (in minutes instead of hours, and adjusted for Daylight Savings Time). Presumably, the user's device and browser should update accordingly to reflect this change, ensuring your script behaves correctly. (If the user's device has the wrong timezone set, it may lead to issues not just with your app but with others until resolved).

While I am not an expert in this area, based on my current knowledge, I believe your approach should work fine. If there are inaccuracies in my explanation, I hope someone more knowledgeable will provide clarification soon.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Unsure about the approach to handle this PHP/JSON object in Javascript/jQuery

From my understanding, I have generated a JSON object using PHP's json_encode function and displayed it using echo. As a result, I can directly access this object in JavaScript as an object. Here is an example: .done(function(response) { var ...

Creating a collapsible accordion feature with jQuery using a specific HTML layout: wanna learn how?

I am looking to create an accordion effect with the structure provided below. The goal is to have the corresponding article toggle when clicking on .booklist>li>a, allowing only one article to be open at a time. Can someone assist me with writing thi ...

The request body is not defined within the Express controller

Currently facing an issue with my controller: when I use console.log(req), I can see all the content of the request body. However, when I try console.log(req.body), it returns as undefined. This problem arises while working on my Portfolio project with Nex ...

Utilizing a refreshed array of elements within a component directive

When working within a view, I am utilizing ng-repeat inside a directive to iterate over an array of objects from my controller. However, as the objects in the array undergo value changes, I encounter a dilemma when transitioning to a new instance of the sa ...

Using TypeScript, implement a function that is called when a React checkbox's state changes to true

Currently, I am experimenting with the react feature called onChange. My goal is to update local data by adding a value when a checkbox is selected. Conversely, when the checkbox is unselected, I just want to display the original data. However, I find that ...

Tips for modifying a particular element within a class?

I am seeking guidance on how to modify a specific class attribute in CSS/JS/JQuery when hovering over a different element. Here is an example: <h1 class="result">Lorium</h1> <h1 class="result">Ipsum</h1> <h1 class="result">Do ...

Binding events within other events can be achieved using D3

Trying to implement code from Scott Murray's book "Interactive Data Visualization for the Web" to create versatile bar graphs. Though the code successfully generates and updates graphs, it seems that the sorting functionality is not functioning as exp ...

Load jQuery results when scrolling to the top of the window

I have a function that triggers when I click a button to fetch more data from my table. I'm attempting to make it work when the button reaches a certain distance from the top of the window, but I've been unable to achieve this so far... $(funct ...

Babel is failing to transpile the Modal component from material-ui-next to ES5

Issue with Babel transpiling Modal component from material-ui-next Here is my .babelrc configuration: { "presets": ["es2015", "react", "stage-1", "stage-2", "stage-3"] } This is the webpack-config.js setup: var webpack = require('webpack'); ...

Steps to configure npm start for an electron application using "babel-node --presets es2015,stage-3"

I've been experimenting with getting my npm start to work properly for electron. Typically, you would start a non-distributed app with electron . or ./node_modules/.bin/electron .. However, due to my use of NodeJS v8.4.0 and ES6/7 syntax, my npm start ...

How can a functional component be created in VueJS using x-templates?

Looking to create a functional component in VueJS with a template as a single-file component? Utilizing x-templates means your component will be stored in a .html file. Want to transform the given component into a functional component? <!-- my_compone ...

What is the best way to wrap the content of a div and include ellipsis at the end?

There is a div on my page that shows some content. What I need is for it to display only the first 10 characters followed by '...' if the content exceeds that limit. 10 characters + '...' I have the option to use either jQuery or PHP ...

Change the data returned by Ajax

After making an ajax request, my table gets populated with data from my array. The return is as expected, but now I want to modify this data before displaying it to the user. Whether this modification happens before or after the data is placed in the table ...

When attempting to integrate Angular 1.4's new router with components, an issue arises where a warning is triggered stating, "Failed to instantiate controller HeadlinesController

Attempting to work with Angular for the first time and struggling to load a component using data from an http request. Currently encountering a warning when attempting to execute the code with the HTTP request. Receiving a "Could not instantiate control ...

Keeping an HTML field constantly refreshed with dynamic content from Django

Imagine having two input fields along with an HTML paragraph displaying a Django value. Field A: <input ...> Field B: <input ...> <p>{{ sum }}</p> The goal is to have the sum update in real time, meaning that once both numbers ...

Creating a dynamic user interface with HTML and JavaScript to display user input on the screen

I'm currently working on creating an input box that allows users to type text, which will then appear on the screen when submitted. I feel like I'm close to getting it right, but there's a problem - the text flashes on the screen briefly bef ...

Invoking a function in a React component from another component

I am trying to implement a page with the structure shown below: const Upload = (props) => { return ( <BaseLayout> <ToolbarSelection /> <Box> <FileDropArea /> </ ...

Manipulating variables in the main controller scope from a function in a transcluded directive scope using AngularJS

How can parent controller scope variables be updated from a transcluded directive scope's function? I have a situation where I am including directives within another directive using transclusion. Here is an example of how it is set up: <my-table& ...

Is AngularJS known for its ability to bind variables across different components effortlessly

In the beginning of my Angular controller, I use Promises to download JSON data and then store it in variables: app.controller('mainController', ['$scope', '$http', '$q', function($scope, $http, $q) { var req1 = $ ...

A sleek Javascript gallery similar to fancybox

I'm currently working on creating my own custom image gallery, inspired by fancybox. To view the progress so far, please visit: I've encountered some issues with the fade effects of #gallery. Sometimes the background (#gallery) fades out before ...