2 weeks past date(mysql)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pradeepjain
    Contributor
    • Jul 2007
    • 563

    2 weeks past date(mysql)

    Hello every one,

    i have a form with a date .i need to display records of the form from the database and display all records of 2 weeks from the present date i.e 14 days record..so how to get the date 14 days back from current date


    Thanks,
    Pradeep
  • hsriat
    Recognized Expert Top Contributor
    • Jan 2008
    • 1653

    #2
    strtotime may hep you.

    Comment

    • pradeepjain
      Contributor
      • Jul 2007
      • 563

      #3
      Originally posted by hsriat
      strtotime may hep you.
      This is the sql command i am using.. i have put "??" for where i have doubt where i need to have a 14 day old date....how to get it i dont know....

      [code=sql]
      SELECT
      ID, raised, ext, location, description, type,
      DATE_FORMAT(rda te,'%d %M %Y'),
      action,status,
      DATE_FORMAT(cda te,'%d %M %Y'),
      remark,handle
      FROM complaint
      WHERE status='open' OR (rdate <= curdate() and rdate >= ??)
      [/code]
      Last edited by Atli; May 30 '08, 07:46 PM. Reason: Added [code] tags and formatted the query to make it readable.

      Comment

      • hsriat
        Recognized Expert Top Contributor
        • Jan 2008
        • 1653

        #4
        Originally posted by pradeepjain
        This is the sql command i am using.. i have put "??" for where i have doubt where i need to have a 14 day old date....how to get it i dont know....

        $str_sql="selec t ID,raised,ext,l ocation,descrip tion,type,DATE_ FORMAT(rdate,'% d %M %Y'),action,sta tus,DATE_FORMAT (cdate,'%d %M %Y'),remark,han dle from complaint where status='open' or (rdate <= curdate() and rdate >= ?? )

        What's the format of rdate?

        Comment

        • Atli
          Recognized Expert Expert
          • Nov 2006
          • 5062

          #5
          Hi.

          You can use the DATE_SUB function to do that.
          [code=mysql]
          SELECT DATE_SUB(NOW(), INTERVAL DAYS 14)
          [/code]

          Comment

          • Atli
            Recognized Expert Expert
            • Nov 2006
            • 5062

            #6
            I've merged the duplicate thread you posted in the PHP forums into this one.
            Please don't double post your questions.

            And please post you code inside [code] tags, preferably formatted in such a way that we can actually understand it.

            Thanks

            Comment

            Working...