Thread: Query problems

Page 2 of 2 First 12
  • Jump to page:
    #16
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Location
    Amsterdam
    Posts
    26
    Rep Power
    0
    I almost converted the whole thing and feeling like I need a beer!

    One more question though, in my mysql database I stored the date in a field with datetype 'datetime'.

    When I wanted to get this info out of de database I used the query:

    Code:
    $query = "SELECT sectionid,subsection,subsectionid,date_format(date, '%d\/%m\/%Y %H\:%i\:%s') FROM content";
    Now in postgreSQL I stored the date in a field with datetype 'timestamp' cause 'datetime' is unavailable in postgres.

    How should I go about getting this date info out of the postgres database?

    Thanx again,
    Hendricus
  2. #17
  3. Me likey breadsticks...
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jan 2003
    Location
    Los Angeles
    Posts
    1,189
    Rep Power
    18
    Use the extract or date_part functions
    http://www.postgresql.org/docs/7.4/s...-datetime.html

    Sorry I know that's not in your language (I'm assuming Dutch?), but hopefully it will be helpful. Basically you could just extract the parts of the date you want and concatenate them into one string (you do string concatenation with || ).

    You may also want to look into SET DateStyle .

    If you can't figure it out, just reply and I'll go into more detail when I got some time.
    PostgreSQL, it's what's for dinner...
  4. #18
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Location
    Amsterdam
    Posts
    26
    Rep Power
    0
    Thanx for the url. And yep it's Dutch.

    I found a solution that works but i'm not sure if it's the nicest
    Here is my solution:

    Code:
    $query = "SELECT sectionid,subsection,subsectionid,to_char(date,'DD-MM-YY HH24:MI:SS') FROM content ORDER BY sectionid,subsectionid";
    $result = pg_query($query) or die("Error");
    
    
    
    while($row = pg_fetch_array($result,NULL,PGSQL_ASSOC))
    	{ 
    $row["to_char"]
    	}
    And

    Code:
    $date = date(Y."-".m."-".d." ".H.":".i.":".s);
    $query = "UPDATE content SET content='$text',subsection='$Sectionname',date='$date',publiek='$public' WHERE sectionid = '$sectionID' AND subsectionid = '$subsectionID'";
    These solutions remind me of math in highschool. I usually got the good answer but a complete wrong way of getting/calculating it

    Cheers,
    Hendricus
Page 2 of 2 First 12
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo