-5

I need to obtain only the time part of a datetime variable without the making it a text file so no varchar

is there a way to get only 9:11:02 from "1/2/2013 9:11:02" without varchar conversion?

yatici
  • 557
  • 4
  • 11
  • 21
  • 3
    What RDBMS are you using? SQL Server? MySQL? Oracle? What version? – LittleBobbyTables - Au Revoir Apr 16 '13 at 20:31
  • What do you mean by text file? – Alex Turbin Apr 16 '13 at 20:32
  • this depend upon your database as well [How to return the date part only from a SQL Server datetime datatype][1] [1]: http://stackoverflow.com/questions/113045/how-to-return-the-date-part-only-from-a-sql-server-datetime-datatype – Haider Ali Apr 16 '13 at 20:33
  • 1
    Do your homework : Have you thoroughly searched for an answer before asking your question? Sharing your research helps everyone. Tell us what you found and why it didn’t meet your needs. This demonstrates that you’ve taken the time to try to help yourself, it saves us from reiterating obvious answers, and most of all it helps you get a more specific and relevant answer! – phadaphunk Apr 16 '13 at 20:34

4 Answers4

1

try this format for mysql

SELECT DATE_FORMAT(tstamp,'%r') AS stamp from table name

E.G.

mysql> select * from test;
+---------------------+
| stamp               |
+---------------------+
| 2013-10-10 09:10:11 |
+---------------------+
1 row in set (0.00 sec)

mysql> SELECT DATE_FORMAT(stamp,'%r') AS stamp from test;
+-------------+
| stamp       |
+-------------+
| 09:10:11 AM |
+-------------+
1 row in set (0.00 sec)
amitchhajer
  • 12,492
  • 6
  • 40
  • 53
1

Something like this

SELECT
CONVERT(VARCHAR(8),GETDATE(),108) AS Time,

OR

SELECT
CONVERT(TIME,GETDATE()) AS TIME
Sachin
  • 40,216
  • 7
  • 90
  • 102
1

If you're using MSSQL, it's still conversion to varchar, but it's data presentation...

SELECT CONVERT(varchar, GETDATE(), 8)
Zoran Causev
  • 360
  • 1
  • 6
1
select CAST('1/2/2013 9:11:02' as TIME)

This will give you the time with a trailing ".00..."

Jeff B
  • 155
  • 7