SQL dates are returning -1 day off - mysql

Trying to capture some information when a user inputs two dates. The information I'm getting back is correct apart from the dates are off by one. So if I ask for 13th 14th 15th I get the correct information back but the dates are 12th 13th 14th.
Found the issue it's to do with BST time being 1 hour ahead. Just not really sure how to rectify it apart from sticking my PC an hour behind.

Check the date stored in the database it might be stored in UTC Format. If it is in UTC Format, you must handle it in your code to match on your time zone.

Related

Add one date to date in MySql

I am setting up a MySQL (Maria) where I am going to upload demo data for an application. In the demo date there will be many different dates from the last 6 months.
What I need to do is to keep all dates the same number of days from today all the time. So a date that is x number of days earlier or later than today keep that interval constant.
The demo data will be used in a PHP application so it is maybe an option to run PHP code to change the dates every day, or is it best done any other way?
I have been trying to just add +1, but it does not work on dates.

How to store recurring events in database for different timezones

We need to store schedules for people in different time-zones, however the schedule repeats either weekly or in a particular day of the month. the problem is we can't store an exact date and can't store time-zone either due to some requirements. the initial solution that we came up with was use three columns :
day => which would specify the day of the recurring event such as "Monday" or "25",
start_time => which would specify the UTC time of the event starting,
end_time => which would specify the UTC time of the event ending.
databaseImageOfEntries
the problem is though if someone has a local time of +10-GMT for example, and they want to store a schedule for the first day of the month in their local time, then the conversion to UTC should give us the last day of the previous month at start_time of "14:00" UTC but some months are not 30 days, so we have no way of storing the correct day in the database since we can't determine what day it will be in each month.
I would really appreciate your suggestions.

Convert date to a month in one time zone when time saved is in GMT - SQL

This is related to an earlier question that I had here: Convert datetime to a fixed date of the month including the time - mysql
I am raising a another question because this is regarding the timezone component in the datetime.
I have a list of date time values that are stored in GMT. For the purpose of a report, I want to convert the dates to a single date of a month. (which was the subject of the previous thread I mentioned above). What I also would like to do is the take the time zone into consideration. I will explain.
The date field is always stored in GMT. But the report is generated for the HQ that is in EST. So when there the dates are converted to a single date time (again, part of the previous thread) only the dates that fall into that month in EST (not GMT) should be changed to that month.
For example, let us say I have this date stored in the table:
2016-04-01 00:03:07 (GMT). But for a person sitting in Eastern time zone this is created in the month of March. So, when I do the conversion of the dates to a specific date of a month, this date should be converted to 2016-03-15 00:00:00 and not 2016-04-15 00:00:00
Pretty challenging to me!
I need this in this format as I am integrating with a third party application
CONVERT_TZ should be able to convert to your required timezone. Then, do the rest of the operations on the result instead of doing them on th original date.

Checking if the UNIX timestamp stored in MySQL DB is this weeks or this months?

I have a MySQL DB, and in one of the tables I have stored the time in which the content was submitted its in the form of a UNIX timestamp, the column is called content_time. Below are two pseudo examples of queries to demonstrate what I'm trying to accomplish, just not sure how to go by doing this (although I understand I will need do some some comparisons between the current and stored timestamps within the WHERE clause):
SELECT * FROM content
WHERE content_time = THIS WEEKS
(the content was posted at any time/day within the current week)
SELECT * FROM content
WHERE content_time = THIS MONTHS
(the month and year from content_time match with the current)
Appreciate all help.
See MySQL's Date and Time Functions, specifically FROM_UNIXTIME(), WEEK() and MONTH(). Keep in mind that when checking is it the same week or month you probably also want to check is it the same year.
Another option is to generate start and end timestamps for the time range youre intrested in (ie timestamp for the beginning of the week and for the end of the week) and then use WHERE(content_time BETWEEN start AND end)

MySql timestamp timezone weirdness

I want to grab records from a table based on the day of the month the record was created.
This information is stored in a Unix timestamp. During testing I created new test records and threw in some timestamps for specific times that I had converted to timestamps using an online converter. I used...
01/29/2010-02:00:00
Right now I'm using...
FROM_UNIXTIME(timestamp, '%d') == 29
This should work for all times on the 29th day of every month. But it is calculating the timestamp to be 5 hours behind the actual value of the timestamp. When I just run a FROM_UNIXTIME on the timestamp it returns 01/28/2010-21:00:00. I was hoping someone could give an explanation for this, if there is an easy fix or should I just code the program to expect the timezone to be a factor.
The FROM_UNIXTIME function automatically converts the datetime to the current timezone.