Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. get minimum date.

get minimum date.

Scheduled Pinned Locked Moved C#
databasehelpquestion
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Nekshan
    wrote on last edited by
    #1

    i have this in database: accessdate 5/2/2007 3/2/2007 2/3/2007 8/3/2007 2/4/2007 2/5/2007 5/5/2007 Now want to access minimum date from it : SELECT MIN(accessdate) FROM tblsummary i shud get : 5/2/2007(as minimum), But i m getting : 2/3/2007(as it is just comparing 2<5 ie date, but not month which is 2<3) Same is happening for max(accessdate) too. How can i rectify it,it wud b pleasure if some1 can help. Thank You in adv. Regards Nekshan.

    V G 3 Replies Last reply
    0
    • N Nekshan

      i have this in database: accessdate 5/2/2007 3/2/2007 2/3/2007 8/3/2007 2/4/2007 2/5/2007 5/5/2007 Now want to access minimum date from it : SELECT MIN(accessdate) FROM tblsummary i shud get : 5/2/2007(as minimum), But i m getting : 2/3/2007(as it is just comparing 2<5 ie date, but not month which is 2<3) Same is happening for max(accessdate) too. How can i rectify it,it wud b pleasure if some1 can help. Thank You in adv. Regards Nekshan.

      V Offline
      V Offline
      virendra patel
      wrote on last edited by
      #2

      SELECT MIN(CONVERT(varchar, DateCreated, 111)) FROM tblsummary

      N 1 Reply Last reply
      0
      • N Nekshan

        i have this in database: accessdate 5/2/2007 3/2/2007 2/3/2007 8/3/2007 2/4/2007 2/5/2007 5/5/2007 Now want to access minimum date from it : SELECT MIN(accessdate) FROM tblsummary i shud get : 5/2/2007(as minimum), But i m getting : 2/3/2007(as it is just comparing 2<5 ie date, but not month which is 2<3) Same is happening for max(accessdate) too. How can i rectify it,it wud b pleasure if some1 can help. Thank You in adv. Regards Nekshan.

        G Offline
        G Offline
        Guffa
        wrote on last edited by
        #3

        Please don't use txtspk. This is a forum, not a text message. Store the dates as dates, not as text. Otherwise you have to convert each value to date in the query to get the aggregate to compare them as dates.

        --- single minded; short sighted; long gone;

        1 Reply Last reply
        0
        • V virendra patel

          SELECT MIN(CONVERT(varchar, DateCreated, 111)) FROM tblsummary

          N Offline
          N Offline
          Nekshan
          wrote on last edited by
          #4

          SELECT MIN(CONVERT(varchar, DateCreated, 111)) FROM tblsummary error in query analyzer: Invalid Columnname 'DateCreated'. 'accessdate' column in 'tblsummary'table has 'datetime' datatype. Did u understand my problem in last post? My query is not checking month. Does 'datetime' datatype takes data in database as 'mm/dd/yyyy'? I inserted data as 'dd/mm/yyyy'.

          1 Reply Last reply
          0
          • N Nekshan

            i have this in database: accessdate 5/2/2007 3/2/2007 2/3/2007 8/3/2007 2/4/2007 2/5/2007 5/5/2007 Now want to access minimum date from it : SELECT MIN(accessdate) FROM tblsummary i shud get : 5/2/2007(as minimum), But i m getting : 2/3/2007(as it is just comparing 2<5 ie date, but not month which is 2<3) Same is happening for max(accessdate) too. How can i rectify it,it wud b pleasure if some1 can help. Thank You in adv. Regards Nekshan.

            V Offline
            V Offline
            virendra patel
            wrote on last edited by
            #5

            date is stored in database in only one way. u have to fatch date as u want in any format. y'r prob solved with above posted ans. query .

            N 1 Reply Last reply
            0
            • V virendra patel

              date is stored in database in only one way. u have to fatch date as u want in any format. y'r prob solved with above posted ans. query .

              N Offline
              N Offline
              Nekshan
              wrote on last edited by
              #6

              yes my problem is solved. datetime datatype stores data in mm/dd/yyyy format. now its working. thank you. :)

              V 1 Reply Last reply
              0
              • N Nekshan

                yes my problem is solved. datetime datatype stores data in mm/dd/yyyy format. now its working. thank you. :)

                V Offline
                V Offline
                virendra patel
                wrote on last edited by
                #7

                which query u r using for fetch min date from database.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups