Skip to content
Advertisement

Tag: datetime

How to separate DATE and TIME from DATETIME in MySQL?

I am storing a DATETIME field in a table. Each value looks something like this: 2012-09-09 06:57:12 I am using this syntax: Now my question is, while fetching the data, how can get both date and time separately, using a single MySQL query? Date like “2012-09-09” and time like “06:57:12”. Answer You can achieve that using DATE_FORMAT() (click the link

Problems with Postgresql CASE syntax

Here is my SQL query: When I execute the above query, I get this error: ERROR: CASE types record and integer cannot be matched From the error message I understand that PostgreSQL take the second select, respectively elapsed_time_from_first_login as a row, even if it will always be a single value (because of the min() function). Question: do you have some

how to cast datetime2 as datetime

I’m trying to convert datetime2 to datetime in order to create a standard between different sources using only SQL or SSIS Take the following SQL query as example: SELECT CAST(offer_start_date AS …

How do I query for all dates greater than a certain date in SQL Server?

I’m trying: A.Date looks like: 2010-03-04 00:00:00.000 However, this is not working. Can anyone provide a reference for why? Answer In your query, 2010-4-01 is treated as a mathematical expression, so in essence it read (2010 minus 4 minus 1 is 2005 Converting it to a proper datetime, and using single quotes will fix this issue.) Technically, the parser might

A way to extract from a DateTime value data without seconds

I have an sql DateTime (ms sql server) and want to extract the same date without the seconds: e.g. 2011-11-22 12:14:58.000 to become: 2011-11-22 12:14:00.000 How can I do this? I was thinking to use DATEADD in combination with DATEPART but seems very error prone (besides performance issues) Answer For a solution that truncates using strings try this: CHAR(16) works

Get DateTime with time as 23:59:59

I’m trying to do a where statement that specifies a DateTime field is between the start and end of the previous month. To do this, I need to specify that the first day of the previous month has a time of 00:00:00 and the last day of the previous month has a time of 23:59:59. This second condition is giving

Advertisement