0

So I've been trying to convert the time in one of the columns in my table. The time column in the table has the format hh:mi:ss but I need it to be in the format hhmiss without the colons; so far I've tried this:

SELECT
    time_utc
FROM
    particle_counter_hisam
WHERE
    time_utc = CONVERT (VARCHAR(8), GETDATE(), 108)

But I get this error:

ERROR: syntax error at or near "," LINE 3: where time_utc = CONVERT(VARCHAR(8), GETDATE(), 108)

I have no clue here why I get this error, please some help would be awesome I am relatively new in SQL.

mitkosoft
  • 5,262
  • 1
  • 13
  • 31
user665997
  • 313
  • 1
  • 4
  • 18
  • Where in the Postgres manual did you find `convert()` and `getdate()`? –  Apr 14 '16 at 06:02
  • I found this command on an sql website, I was trying to find someone that has tried to dot he same thing than me and that is what I found. – user665997 Apr 14 '16 at 13:48

1 Answers1

3

You can use to_char in postgresql:

SELECT TO_CHAR(time_utc, 'hh24miss')
FROM particle_counter_hisam
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
nathan hayfield
  • 2,627
  • 1
  • 17
  • 28
  • that sort of worked, but I in my data the times are recorded as 15:34:17 and after i used your code it only output 033417 , instead of 153417, the other thing is that i need this changes to be made in the table permanently. It only a data output of that specific column without changin anything in the table. – user665997 Apr 13 '16 at 23:00
  • You can try HH24 instead of hh, yes what gordon said. The database itself has a standard format it will use. You can only change the output. – nathan hayfield Apr 13 '16 at 23:02
  • I see, is there a way to change the standard format, because I really need to change the time stamp into the ouput i am getting. In other words can you even modify your table at all? – user665997 Apr 13 '16 at 23:06
  • No the database has a format it takes but provides many options for output. – nathan hayfield Apr 13 '16 at 23:09
  • can you save your output as a .csv file? – user665997 Apr 13 '16 at 23:11