I´ve got the following table (column) in DB2:
TIME
04:30
05:00
...
This time is storaged as character Why someone did this is not clear to me. I would like to know how to convert this time into 'HH:MM' or 'HHMM' time format with DB2 SQL. The goal is to work with min(time) and max(time) afterwards. I haven´t been able to find an example here. Any hints?
Thank you!
(I hope the description is clearer now)
You can use the following SQL statement if you have not tried it already:
'SELECT CONVERT(TIME, '06:30');'
Related
I am migrating Greenplum to HiveSql but i could not able to find any such below kind of solution in google search. please help me.
DATE_PART('minute',ck_2::time - ck_1::time) gap_1_2
please help me , how do we convert above the statement to hivesql.
If i am not wrong ask here is time difference in minute for hive,
it can be achieved using unix_timestamp it covert time in second and then devide it by 60 and get time difference in minute
ie -
SELECT (( unix_timestamp(ck_2) - unix_timestamp(ck_1))/60 ) as gap_1_2
I wondered if anyone can help. I need to get the date and time an sql query was run. I would like the output to be in the following format; YYYY-MM-DDThh:mm:ss Does anyone know what sql to write get this information please?
Thanks
You can select the current timestamp in the query. The standard SQL for that is:
select . . ., current_timestamp
from . . .
Most databases support this. However, there are also bespoke methods such as getdate(), now() and sysdate.
I am using "CURRENT_TIMESTAMP" for automatic date setup inside the column for each row in SQL. It shows date and time but time is wrong. please help.
CURRENT_TIMESTAMP will show you the server timestamp not client side timestamp from where you are querying.
Please check in which timezone your database server is located.
A timeclock table in SQL is storing TimeIn/TimeOut as 1:00p in a format which when i export into excel will not let me subtract and get the time difference.
I was trying to run a query in SQL and convert the times within SQL so that when i export i can subtract. In Access i was using CVDate.
This is the sql code i tried using:
Convert (varchar(6), dbo.tblPayrollFlashPunch.TIME_IN, 108) as TimeIn,
CONVERT (varchar(6), dbo.tblPayrollFlashPunch.TIME_OUT, 108) as TimeOut,
Any help will be appreciated, btw I am very new to SQL and we are running SQL 2008.
Below is a snapshot of sample data.
(Original here: http://i.stack.imgur.com/AS8BS.gif )
Edit: I was hoping SQL could do the conversion so that i could pull the data through a view directly into excel and have the correct format so that my formulas work. Also, I've tried changing the formats in excel with no success. In MSAccess you can use CVDATE and works great.
Edit 2: Being the noob that I am i just realized we are running SQL Server 2005 which explains why i cant use many of the suggested functions.
Which SQL are you using?
In T-SQL, I believe this would work if your time column is a string/varchar.
CONVERT(TIME, (dbo.tblPayrollFlashPunch.TIME_OUT + 'm'), 108) as TimeOut
What about using DATEDIFF in TSQL to get the difference straight from there?
I am running some queries to track down a problem with our backup logs and would like to display datetime fields in 24-hour military time. Is there a simple way to do this? I've tried googling and could find nothing.
select to_char(sysdate,'DD/MM/YYYY HH24:MI:SS') from dual;
Give the time in 24 hour format.
More options are described here.
If you want all queries in your session to show the full datetime, then do
alter session set NLS_DATE_FORMAT='DD/MM/YYYY HH24:MI:SS'
at the start of your session.
Use a to_char(field,'YYYYMMDD HH24MISS').
A good list of date formats is available here
It's not oracle that determines the display of the date, it's the tool you're using to run queries. What are you using to display results? Then we can point you to the correct settings hopefully.