Jump to content

Help In Sql Query For Extract Hour In Timestamp From Column


Recommended Posts

Posted

I’m using below query… Getting month and date but not hour while extracting from table …throwing error
Hour line add cheyaganey An unexpected token "EXTRACT(month FROM DT_SVC_STARTD) "month", EXTRACT(day" was found following "SELECT ". Expected tokens may include: "<space>". SQLSTATE=42601
select extract(month from DT_SVC_STARTD) as mon,
extract(day from DT_SVC_STARTD) as dy,
--extract(Hour from DT_SVC_STARTD) as hh
count(DT_SVC_STARTD) as Trans
FROM UDBADM.RDSTMP where extract(year from DT_SVC_STARTD) > 2011
group by extract(month from DT_SVC_STARTD),extract(day from DT_SVC_STARTD)
--extract(Hour from DT_SVC_STARTD)
order by mon,dy;

using rapidsql tool over sybase..datetime format "2011-12-11-07.56.07.651000"
need to figure out peak hour transaction from a year...year lo e month lo e date e hour lo inni trasactions jariginooo kavali

Posted

ee extract endi???

SQL lo ee function kosam DATEPART anedi undi kada... use that.. google chey DATEPART ani... DAY MONTH YEAR HOUR MINUTES SECONDS anni vastai... use that..

Thanks

Posted

You can also use substring function in sql to extract a part of any string.


substring([i]expression[/i], [i]start, length[/i] )

Posted

[quote name='dravia' timestamp='1362075661' post='1303345233']
You can also use substring function in sql to extract a part of any string.


substring([i]expression[/i], [i]start, length[/i] )
[/quote]

substring aaa... DATEPART ani built in function untey malli calculated field enduku... Anavasaram aina overload tappa query meeda... Use like this...

SELECT GETDATE() AS 'TimeStamp'
, DATEPART(D,getdate()) AS 'Day'
, DATEPART(M,getdate()) AS 'Month'
, DATEPART(YYYY,getdate()) AS 'Year'
, DATEPART(HH,getdate()) AS 'Hour'
, DATEPART(MINUTE,getdate()) AS 'Minute'
, DATEPART(SECOND,getdate()) AS 'Second'

Posted

[quote name='loveindia' timestamp='1362076036' post='1303345252']

substring aaa... DATEPART ani built in function untey malli calculated field enduku... Anavasaram aina overload tappa query meeda... Use like this...

SELECT GETDATE() AS 'TimeStamp'
, DATEPART(D,getdate()) AS 'Day'
, DATEPART(M,getdate()) AS 'Month'
, DATEPART(YYYY,getdate()) AS 'Year'
, DATEPART(HH,getdate()) AS 'Hour'
, DATEPART(MINUTE,getdate()) AS 'Minute'
, DATEPART(SECOND,getdate()) AS 'Second'
[/quote]

adi just an alternative ki cheppa :police:[size=4] ..[/size][size=4] [/size]

Posted

ela cheptaavu vayya alternative ani... takita takita takita 2 4.. takadimi takadimi 2 6.. aa tempo enti ee tempo enti.. aa query enti ee query enti.. :P (Just for fun)

Posted

EXTRACT(HOUR FROM timestamp) ...i guess your question is resolved...

Posted

[quote name='dravia' timestamp='1362075661' post='1303345233']
You can also use substring function in sql to extract a part of any string.


substring([i]expression[/i], [i]start, length[/i] )
[/quote]
please bhaiyya thana question enti meeru emi answer esthunaru ...i didnt get you

Posted

[quote name='m8espartan' timestamp='1362077261' post='1303345333']
please bhaiyya thana question enti meeru emi answer esthunaru ...i didnt get you
[/quote]

[size=4][font=arial, sans-serif]substring("YYYY-MM-DD HH:MM:SS",12,13) returns HH,anything wrong?[/font][/size]

Posted

[quote name='dravia' timestamp='1362077640' post='1303345358']
[size=4][font=arial, sans-serif]substring("YYYY-MM-DD HH:MM:SS",12,13) returns HH,anything wrong?[/font][/size]
[/quote]
this will not work..... substring is just used to give part of that string.... ikkada date part function vadali.....

Posted

[quote name='goli soda' timestamp='1362077879' post='1303345394']
this will not work..... substring is just used to give part of that string.... ikkada date part function vadali.....
[/quote]

k Thanks..

Posted

dude yee problem solve ayinda? nuvvu sybase annavu... but extract command sybase lo ledu kada......

Posted

[quote name='goli soda' timestamp='1362155958' post='1303349856']
dude yee problem solve ayinda? nuvvu sybase annavu... but extract command sybase lo ledu kada......
[/quote]
Alelooya, same qochen goli

×
×
  • Create New...