I'm trying to figure out how to pass in the date to create event. It says in MS and I'm not sure how to convert the date/time to MS without having a date to start from.
When we say milliseconds we mean a unix timestamp in ms. See https://en.wikipedia.org/wiki/Unix_time for a definition. In javascript it would be the DateTime.getTime() function.
Related
I was wondering if there was a way to store a date (example: 01/01/2013) as datetime without SQL Server CE adding the time (example: 12:00:00 AM).
I could always store it as the string "01/01/2013" but I really want to be able to compare the dates on querying the database.
I realize that as long as I only stored the date part, all of the times in the datetime field would have equal values (i.e. 12:00:00 AM), so comparing them wouldn't be a problem and I could just always ignore the time part, however, it seems ridiculous to have this unnecessary data appended to every entry in the table.
Is there a way to store only the date part of the datetime as datetime so that the dates can still be compared in the SQL query or do I just need to live with this overhead and move on?
Side Note:
I just spent the last 30 minutes searching Google and SO for an answer I was sure was already out there, but to my surprise, I couldn't find anything on this issue.
Update:
The conclusion I have come to is that I will just accept the time in the datetime format and let it always default to 12:00:00 AM by only adding the date part during the INSERT statement (e.g. 01/01/2013). As long as the time part always remains the same throughout, the dates will still be easily comparable and I can just trim it up when I convert it to string for screen display. I believe this will be the easiest way to handle this scenario. After all, I decided to use SQL for the power of its queries, otherwise, I might have just used XML instead of a database, in the first place.
No you really can't get rid of the time component. It is part of the data type defined by sql server. I was very annoyed by it until I found that I could still display the dates without the time using JQuery to reformat them with the date formatter plugi:
https://github.com/phstc/jquery-dateFormat
Good Luck!
select CONVERT(date, GETDATE())
I've found a few questions on this but none seem to fit my problem case quite right.
Overview: Data is in Oracle 10g database, requirement including using MS Access as a front end.
Problem: The tables include date fields which are incompatible with MS Access. I NEED to run queries based on date and time in MS Access
Details:
I'm not allowed to redesign the tables
Decided to create new tables on the server and run inserts from the old tables to the new
Probably sounds weird but given the constraints I'm allowed to do what I want if I duplicate the data
With the new tables I want to take the date/time/timezone field from the old and insert it into a new table with the date/time but strip the timezone, put it in a field by itself
The big requirement is to have the data be usable. If I do a TO_CHAR it becomes a string and I can't setup queries based on date and time with that as it's a static text field at that point.
Any help is appreciated! Thanks !!!
If possible the best way I have found to deal with these issues is to link to the table via a view. You can then present the data how you wish under the hood without having to alter the table structures.
I found an answer for this. Looking here:
Oracle Date Functions
They give some samples wrapping a to_char with to_date. I formatted this in a way to convert it to text stripping the time zone then wrapped it with the to_date to convert it back to a date and time field that's compatible with MS Access. Here's the code:
SELECT TO_DATE(TO_CHAR(table.date, 'DD-MON-YYYY HH24:MI:SS'),'DD-MON-YYYY HH24:MI:SS')
FROM table.date;
I'm trying to convert the datetimeOffset stored in SQL Azure to UTC DateTime so that I can perform a proper calculation.
The DateTimeOffset is stored as local NewZealand Time as:
2011-05-31 21:40:00.0000000 +10:00
I need to convert the above values to UTC so that I can perform date time calculation. Is there any way to achieve this using TSQL and Azure SSRS?
Thanks heaps.
Here's another thread that may give you some ideas: TSQL: How to convert local time to UTC? (SQL Server 2008)
Off the top of my head, if you know the datetime you are working with is from New Zealand, you know what the UTC offset is. It should be based on one of two values (if they have daylight savings).
So do a dateadd with a function call that determines if you are in daylight savings or not. How do you determine if you are in daylight savings for a given date? Good question. Unless there is a .NET function you could turn into a CLR function, I would just create a look up table and a function that tests against that. The function either returns a boolean or the proper offset for New Zealand.
I would save the new derived value into a new column, but I'm not sure what your needs are.
How do I use an SQL statement on an sqllite database to insert the current date in UTC. I found the NOW function but what format is that in? This will be on mobile devices so everyone will have a different locale, however, I need a standard time format because the device will compare the dates with my server.
Also, is there a way to automatically update a 'modified' field when the data in the row is changed like you can in MySQL?
SELECT DATETIME('now') returns the current UTC datetime. See Date And Time Functions. You can use DATETIME DEFAULT CURRENT_TIMESTAMP with column declaration.
Format 11, the string 'now', is
converted into the current date and
time as obtained from the xCurrentTime
method of the sqlite3_vfs object in
use. Universal Coordinated Time (UTC)
is used
For the 'modified' field you can use a trigger.
You don't specify what you use to develop your application on. I prefer using QDate::toJulianDay and QDate::fromJulianDay in Qt to store dates in an SQLite database as an integer if I only need to store the date.
I have a database with DateTime fields that are currently stored in local time. An upcoming project will require all these dates to be converted to universal time. Rather than writing a c# app to convert these times to universal time, I'd rather use available sqlserver/sql features to accurately convert these dates to universal time so I only need an update script. To be accurate, the conversion would need to account for Daylight savings time fluctuations, etc.
A User Defined Function would allow you to write an SQL query that looks like this:
SELECT toUTC([MyDateColumn], [MyTimeZoneColumn]) FROM [MyTable]
Then you get universal times back from the server without a lot of ugly syntax in the query itself. Now you could build the UDF for this with regular SQL similar to what Chris posted, but SQL Server 2005 and later will let you build the UDF using CLR (.Net: C# optional) instead. It has much better support for dates and can do a better job taking timezones and daylight savings time into account.
check out the convert function and the getutcdate function?
http://msdn.microsoft.com/en-us/library/ms187928.aspx
Check out this link from CodeProject.com - it does exactly what you want: take a date and a time zone, pass them to a UDF, and get the date in UTC or any other time zone.
IMPORTANT: Check the comments of that article - the author wasn't allowed to revise the article after a certain point, and there is an updated version of the code used for the UDFs in the comments that addresses some issues not found in the original article code.
ALSO IMPORTANT: Don't use this for querying large data sets. It's perfectly fine for a one-time load into a database, or for returning a UTC date for a single row (like a user login table or what have you.)
If you want performance, the only really acceptable method for time zone conversion is to have a lookup table that handles every possible time zone conversion for every single hour in a year, with a case statement to handle rollovers between years (ie December 31 - January 1 or vice versa.) Yes, the table is huge, but the query performance is nil.
SQL Doesn't have anything built in for this.
Two ways would be the C# application (you mentioned you don't want) or writing a really complicated update statement with something like:
UtcDate = DATEADD(hour, CASE WHEN OriginalDate BETWEEN x AND y THEN 4
WHEN OriginalDate BETWEEN x2 AND y2 THEN 5 ... END, OriginalDate)
Note - I'd recommend the C# app plus something like TZ4Net to handle the conversion.