Thread: date_sub

    #1
  1. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2002
    Posts
    607
    Rep Power
    13

    date_sub


    Hi,

    How do I perform a date_sub in pgSQL? I need to return only rows from X days ago. I was told this is what to use in mysql, but it won't work in pgsql.
  2. #2
  3. No Profile Picture
    Artist, DB Geek, Spamkiller
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Location
    Budapest / San Francisco
    Posts
    3
    Rep Power
    0

    maybe like this...


    assuming you have some kind of created/updated timestamp on your table, you should be able to do something like:

    select name, email
    from customers
    where last_order >= current_timestamp - interval '3 days'


    ... where last_order is a timestamp and 3 is the number of days of recentness you want.


    hope this helps a little. i don't know of any way to access rows by date without actually having date or timestamp columns in them to refer to.

IMN logo majestic logo threadwatch logo seochat tools logo