38 users online (1 members and 37 guests)  


  Results 1 to 2 of 2

Related

  1. .cn$5.76 per year!!!    Forum: Domain Name Sales
    Replies: 0
  1. #1
    blink's Avatar
    New User

    Status
    Offline
    Join Date
    Mar 2005
    Posts
    19

    How to get year, month and day from PostgreSQL datestamp?

    Hello,

    I have to count database entries for specific months and I cannot figure out how to group the results by months:

    select datestamp, count(hits) from users group by datestamp

    This will group hits by the whole timestamp including minutes and seconds, but how can I group the results by the months?

  2. #2
    QuietDean's Avatar
    Administrator

    Status
    Offline
    Join Date
    Oct 2000
    Location
    Bournemouth, UK
    Posts
    2,662

    Re: How to get year, month and day from PostgreSQL datestamp?

    Hiya,

    I'm more of a mySQL man myself, but if I remember correctly to_char is a good way to get specific date formatting:

    select to_char(datestamp, 'month') from users group by to_char(datestamp, 'month')

    The only thing I'm not sure about is whether you can just dump the function in there in that manner. Try it and see, le us know.
    If one of our members helps you, please click the icon to add to their reputation!
    No support via email or private message - use the forums!
    Before you ask, have you Searched?



Tags for this Thread