SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: using dayname()

  1. #1
    SitePoint Member
    Join Date
    Oct 2005
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    using dayname()

    Hopefully this is an elementary question that I just can't seem to get my head around. I'm far from being a master in queries. Can I query for records using the name of the day of the week in my date field? In other words find all the records that have a Saturday as the date when my date field is saving the date in this format (2004-07-10)? Didn't know how I could use dayname() in my query to get the results, if at all. I don't want to display the day name ("Saturday"), I would like to use it in my query. Kind of like this, which I know is not valid

    SELECT var1, var2, date FROM table a WHERE dayname(date)=Saturday

    Any help is appreciated
    Thanks

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,341
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    WHERE DAYOFWEEK(datecolumn) = 7
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Member
    Join Date
    Oct 2005
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    worked like a champ. I knew I was asking a dumb question. Don't know why I didn't think of doing it that way, but thanks for making me feel like an idiot. Sometimes, you just need to be reminded!

    Thanks again,
    Scott

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,341
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    oh come on, you weren't an idiot, you were on the right track

    this would work too --

    WHERE DAYNAME(datecolumn) = 'Saturday'

    it's just more typing
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •