I have different users having different timeznoes. Suppose , one user has timezone set as GMT-8:00 (America/Los_Angeles) another has GMT+5:30 (Asia/Kolkata). I have one mysql function which returns current local date time on basis of user.
SELECT CONVERT_TZ(CONCAT(UTC_DATE(),' ',UTC_TIME()),'+00:00','-08:00');
Now this is not considering DST timezone. So how to find whether timezone is currently following DST and get date time on basis of that.
Related
The table doesn't have any date time column. I want to if there is any inbuilt keyword which can does that.
I want to know all commits done after a particular date.
If flashback is enabled on the database you can get records on the table in an around a particular date range in Oracle.(It purely depends on if its enabled and for how long the flashback needs to be kept)
You can query to see the data in the table as of 3 days back as follows
select *
from table as of timestamp sysdate-3
I am hoping that someone can help me a SSRS Subscription/Report Query. I have a report that takes 2 date parameters as default startdate = 1st Date of the Current Month, enddate = today's date e.g. startdate = 01/05/2017 enddate = 17/05/2017.
Though these are default dates when the report is run you can also after the initial run change these dates to anything else that you want.
What I want to do is set up a subscription service that runs on 1st of the month and sends the report to a folder on the network.
What I want to do though is replace the startdate and enddate at the point the subscription is run with the startdate and enddate of last month e.g. on the 1st of May the startdate = 01/04/2017 and enddate = 30/04/2017.
What I thought I would do is create a stored procedure in my report with the relevant dates on it for all scenarios that I will need. Set the Last Month one's with default values from the procedure.
Now I can see all date parameters that I might need within the subscription set up but I cant see how I can change the default run time ones when the report is just run on a daily basis by a user to the ones I need it to run for the last month. I know I could just create another report to do this but it seems silly to have multiple reports with only the dates differing and I going forward I am likely to use this logic on other date ranges.
The initial code and idea came from this link "SQL Server: calculating date ranges"
Thanks
Hi R.Richards, since posting the initial query I have been testing a few things with Data Drive Subscription and I think that one of the issues may be due to date format. My report parameters are just set up as date/time but as stated I am wanting to use a function/procedure to call the relevant date splits. The code I am using is in the link that I posted to the original query but I can post it here as well if it helps. When using data driven, if I just use the date default in the report there appears to be no issue but when I select it from the function it errors, the function returns year/month/day timestamp but when I see my defaulted date in the parameter its day/month/year timestamp??
Thanks Phil
I am looking for a way to create a View that when queried will automatically only retrieve new records since the last query. My tables have a timestamp field for all entries, so for a simple example I can
SELECT * WHERE timestamp >= 'blah'
but I don't know how to determine what blah should be from the last query. So if the View was queried at 11:00 and then again at 12:00, the query at 12:00 should only return records added since 11:00. And so on... This all needs to be accomplished in the View, the end user should simply be able to query the View and get the results.
Is this possible?
There are two ways:
Store last access date time in database per user persistent session
table, if you have one. On next view call to database, use the
previous latest access time in the session to filter rows starting
from.
Store last access date time in user virtual session at client
environment. On every call to server, send last access date time as
well. So that server uses it to filter rows starting from.
I prefer to use second option that process won't write any data in database tables.
As there may be an unread record that slips through undetected (say it came less than a second since the last one accessed, so it has the same timestamp), set a column to auto increment (typically labelled id) and check for entries using it e.g. in PHP save the last accessed record in a $lastId variable, and use:
$sql="SELECT * WHERE `id` > '$lastId'";
I am new to database development and am currently working in MySQL.
I have a column that contains all the time zones for USA. I want to be able to get the current time (only time, no date) as of right now for each time zone in each row.
The TimeZone data looks like: +05:00, -03:00 etc etc etc
This is how I have attempted it. I have 2 tables, one country, one city. TimeZone is found within "city" table. I have tried to use the function sys date() but it returns the complete date and the current time on my system, not based on the time zone. Can anyone help me out? Thanks a lot
select TimeZone, Country, sysdate() as "Current Time"
from city, country
where Country='USA' and city.CountryId= country.CountryId;
You should be able to use the convert_tz function:
SELECT CONVERT_TZ(NOW(),'-07:00', city.TimeZone) AS Time, city.Name
FROM city, country
WHERE country.Name='USA' and city.CountryId= country.CountryId;
Assuming your server is in -07:00 timezone.
I'm trying to retrieve all the entries of the day in my model:
where('date(created_at) = date(?)', Date.today)
But, because of the timezone (My local time is UTC+2), I don't have the expected result. For example, if an entry has been created one minute after midnight, in the database, it will be stored at 22:01 (so not "Date.today").
Is there a way to do that ?
EDIT:
As the admin of the website, I want to display the number of the entries on my local time "today" (It's only for statistics purpose!). So I want to keep timestamps store in utc, but convert them to my local timezone during this request!
You can set the correct time zone in several ways. One is described in this answer:
https://stackoverflow.com/a/6118837/567126
adding following to application.rb works
config.time_zone = 'Eastern Time (US & Canada)'
where('date(created_at) = ?', Time.zone.now.to_date)
Time in the database should be stored as UTC. This way, when you do a worldwide website, you can serve each user with their own timezone.
It's the UI (views) responsibility to show the time in the user's local timezone.
For your where you should use Time.now.utc
This way, you are searching the DB with the common UTC.