Tag Archives: datetime

Sql Server using DateTime as Primary Key

Questions: Hi my questions is similar to: MySQL: Using DATETIME as primary key But I’m specifically interested in Sql Server and I want to approach the question practically with a specific scenario in mind rather than theoretically as in the other post. I want to store events/actions that users perform. The odds of more than… Read More »

Why CAST('20140904 23:59:59.999' AS datetime) equals '2014-09-05 00:00:00.000'? [duplicate]

Questions: This question already has an answer here: T-SQL Query Returning Items It Shouldn't Be 5 answers Answers: datetime values are rounded to increments of .000, .003, or .007 seconds I think you should use SELECT CAST(‘20140904 23:59:59.997’ AS datetime) This returns: 2014-09-04 23:59:59.997 You can find more information here: http://msdn.microsoft.com/en-us/library/ms187819.aspx This is the accuracy… Read More »

MS SQL select a datetime by month?

Questions: How do you select a datetime column by month? TABLE A TITLE MY_DATETIME blah 2011-03-26 05:44:43.213 SELECT * FROM TABLE A WHERE MY_DATETIME = “August” Answers: SELECT * FROM TABLE A WHERE DATEPART(month, MY_DATETIME) = 8 Or, less reliably based on language setting: … WHERE DATENAME(month, MY_DATETIME) = ‘August’ Questions: Answers: SELECT * FROM… Read More »

How to convert a byte[] into datetime in C#?

Questions: I have a field of type TimeStamp in database, which is converted in byte[] in c# code, and i need to convert it to DateTime value. So i want to convert from an array of bytes into DateTime. Already used this code: byte[] byteValue = someValue; long longVar = BitConverter.ToInt64(byteValue); DateTime dateTimeVar = DateTime.FromBinary(longVar);… Read More »

Group DateTime into 5,15,30 and 60 minute intervals

Questions: I am trying to group some records into 5-, 15-, 30- and 60-minute intervals: SELECT AVG(value) as “AvgValue”, sample_date/(5*60) as “TimeFive” FROM DATA WHERE id = 123 AND sample_date >= 3/21/2012 i want to run several queries, each would group my average values into the desired time increments. So the 5-min query would return… Read More »

How to format cell with datetime object of the form 'yyyy-mm-dd hh:mm:ss' in Excel using openpyxl

Questions: So, given: dttm = datetime.datetime.strptime(“2014-06-23 13:56:30”, “%Y-%m-%d %H:%M:%S”) ws[‘A1′] = dttm The result in excel is that the correct date-time is written to the cell (you can see it where you’d input formulas). BUT, the cell display format is only MM/DD/YYYY. I need the cell to display like “6/23/2014 13:56” instead of just “6/23/2014”.… Read More »