selecing dates

Discussion in 'MySQL' started by dizyn, Feb 29, 2008.

  1. #1
    I want to select date after 2 days but don't want to count Saturday and Sunday.
    Here is my current query which picks date simply after 2 days.
    SELECT DATE_ADD('2006-05-00',INTERVAL 2 DAY);
    Code (markup):
    I want it to exclude Saturday and Sunday if Saturday and Sunday is coming it should cross 2 days.

    thank you
     
    dizyn, Feb 29, 2008 IP
  2. AstarothSolutions

    AstarothSolutions Peon

    Messages:
    2,680
    Likes Received:
    77
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Why not do the date element before passing it to the SQL?

    Alternatively have a stored proc/ function that checks the day of the week first, if it is a Thurs or Fri or Sat add the appropriate number of days if it is Sun, Mon, Tues then add 2 days. Once you have the date feed it into the sql query
     
    AstarothSolutions, Feb 29, 2008 IP
  3. MrGamma

    MrGamma Peon

    Messages:
    26
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Does anyone know why any of the date MySQL statements are any better than a unix timestamp?

    Unix timestamps are sooooo much easier to work with...
     
    MrGamma, Mar 6, 2008 IP
  4. uppaluri

    uppaluri Peon

    Messages:
    33
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    SELECT  case weekday(now()) when 3 then DATE_ADD(now(),INTERVAL 4 DAY) when 4 then DATE_ADD(now(),INTERVAL 3 DAY) else DATE_ADD(now(),INTERVAL 2 DAY) end;
    Code (markup):
    returns next Monday if current day is Thursday or Friday, else returns a date that is 2 days away.

    any good this one ?
     
    uppaluri, Mar 8, 2008 IP