In my table, I have a column 'send_time', which is String:
2018-07-04 09:15:05
If I want to select all records after 2018-07-04, how to write that SQL statement?
You can use to_date function.
to_date(send_time) > '2018-07-04'
Related
I have a date column in a table which is named released_date and the format of its data is for example: 01-Jan-1995. I want to have just the years which are greater than 1997. Does anybody know how I can write such query?
if the date is in dd-MMM-yyyy format, you can use regexp_extract:
select regexp_extract (released_date, '(\\d{4})$',1) as year
Try this:
SELECT * FROM table_name WHERE year(released_date) > 1997
Hi I want to find the oldest date from a string date column in format 20180209 00:00:00.
I am using the following query to get the string column in date format
select from_unixtime(unix_timestamp(acc_last_change_date, 'yyyyMMddHHmmss')) from ACCOUNTS
but the result is returned as null.
Could you help me on same.
Just use min():
select min(acc_last_change_date)
from accounts;
Your string is in a suitable format for using min().
If you want the entire row, you can use:
select a.*
from accounts a
order by a.acc_last_change_date
limit 1;
I have different numbers looking like 40825 and I want to convert them to an actual date in Oracle SQL.
I know it should be SELECT TO_DATE(40825 ,'MM-DD-YYYY') in SQL Server, but this does not work with the same syntax in oracle SQL.
Any help?
If this number mean 4 day, 8 month, and year 2025 then, u must use to_date function with string (not nubmer) and string must looks like date mask.
SELECT TO_DATE(to_char(40825,'FM000000') ,'MMDDYY') FROM dual
I see that a table has the data value as 18-May-2012. But when I query looking for the same date using the below query, no results are available.
Select Submit_Dt From Siebel.S_Order_Dtl
where submit_dt = '18-May-2012'
Could you help me sort this issue?
You need to convert string date into date with TO_DATE() function.
Also you need to take into account that your date might contain hours/minutes/seconds. In order to handle this you need to truncate submit_dt column.
In your case it would look like this:
Select Submit_Dt From Siebel.S_Order_Dtl
where TRUNC(submit_dt) = TO_DATE('18-May-2012','dd-MON-yyyy')
Try to convert the date to date format using to_date as below
Select Submit_Dt From Siebel.S_Order_Dtl
where submit_dt = to_date('18-May-2012','DD-MON-YYYY')
I am attempting to move a stored procedure from Microsoft SQL Server 2000 to Informix 11. The original SP contains a final select statement with a GROUP BY statement that includes a converted datetime:
group by convert(varchar(8), c.startDateTime, 1)
When I convert this to Informix syntax I get a syntax error at run time:
GROUP BY (c.startDateTime::DATETIME YEAR TO DAY)::VARCHAR(10)
Can anyone please point me to how, if possible, this can be done in Informix? If this is not possible, which I suspect, how would you typically handle this in the overall query?
I think you need to convert from this:
SELECT a, b, c
FROM ...
GROUP BY (c.startDateTime::DATETIME YEAR TO DAY)::VARCHAR(10) ;
to something like:
SELECT a, b, c,
(c.startDateTime::DATETIME YEAR TO DAY)::VARCHAR(10) AS d
FROM ...
GROUP BY 4 ; --- meaning: the 4th column in the SELECT clause
In Informix, it is generally not required to convert datetime fields to character strings to manipulate them. Instead, use the extend function.
Example, if c.StartDateTime is defined as a datetime year to second e.g. 2012-10-28 23:00:00 and you want just the date portion, use extend (c.StartDateTime, year to day). This will return 2012-10-28.
Are you converting to Informix syntax for dates to varchar in mm/dd/yyyy (mssql style=1) as
TO_CHAR(c.StartDateTime,"%m/%d/%iY")
???