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. Web Development
  3. ASP.NET
  4. Get records between Today and 2 years from input date

Get records between Today and 2 years from input date

Scheduled Pinned Locked Moved ASP.NET
csharpasp-nethelp
8 Posts 2 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.
  • M Offline
    M Offline
    munklefish
    wrote on last edited by
    #1

    I am using Asp.Net 2.0 (c#) and SQL2005. I have a simple table with following info: Column 1: bigint - unique id count field Column 2: varchar - name of organisation Column 3: DataTime - date record added I basically need to show those records that are still valid. By valid i mean those records which have have an input date (column 3) of upto 2 years ago. Once the input DateTime is more than 2 years ago the record should no longer be shown. Please can you give me help / ideas / info on how i can acheive this. Many many thanks in advance!

    B 1 Reply Last reply
    0
    • M munklefish

      I am using Asp.Net 2.0 (c#) and SQL2005. I have a simple table with following info: Column 1: bigint - unique id count field Column 2: varchar - name of organisation Column 3: DataTime - date record added I basically need to show those records that are still valid. By valid i mean those records which have have an input date (column 3) of upto 2 years ago. Once the input DateTime is more than 2 years ago the record should no longer be shown. Please can you give me help / ideas / info on how i can acheive this. Many many thanks in advance!

      B Offline
      B Offline
      Blue_Boy
      wrote on last edited by
      #2

      In T-SQL this is one of the possibilities: declare @date as varchar(15) set @date = '2008-04-15' //here u give input parameter select * from myTable where Datetime >= convert(varchar(15),cast(@date as datetime),102) and datetime<= convert(varchar(15),(cast(@date as datetime)-365*2),102) instead format date 102 use ur according format Hope it helps...


      I Love T-SQL

      modified on Tuesday, April 15, 2008 7:20 PM

      M 1 Reply Last reply
      0
      • B Blue_Boy

        In T-SQL this is one of the possibilities: declare @date as varchar(15) set @date = '2008-04-15' //here u give input parameter select * from myTable where Datetime >= convert(varchar(15),cast(@date as datetime),102) and datetime<= convert(varchar(15),(cast(@date as datetime)-365*2),102) instead format date 102 use ur according format Hope it helps...


        I Love T-SQL

        modified on Tuesday, April 15, 2008 7:20 PM

        M Offline
        M Offline
        munklefish
        wrote on last edited by
        #3

        Thanks for the help!!!!! However my SQL knowledge is limited, and i dont know what you mean about '102 date format'. My dates arebeing stored in the format: '15/04/2008 00:00:00' eg Month/Day/Year. Which code do i use for this? Thanks again.

        B 1 Reply Last reply
        0
        • M munklefish

          Thanks for the help!!!!! However my SQL knowledge is limited, and i dont know what you mean about '102 date format'. My dates arebeing stored in the format: '15/04/2008 00:00:00' eg Month/Day/Year. Which code do i use for this? Thanks again.

          B Offline
          B Offline
          Blue_Boy
          wrote on last edited by
          #4

          The 102 datetime format gives u this format yyyy.MM.dd Try to run that code on Query Analyzer and see if it is according to your need, if not then fell free to ask ;)


          I Love T-SQL

          M 1 Reply Last reply
          0
          • B Blue_Boy

            The 102 datetime format gives u this format yyyy.MM.dd Try to run that code on Query Analyzer and see if it is according to your need, if not then fell free to ask ;)


            I Love T-SQL

            M Offline
            M Offline
            munklefish
            wrote on last edited by
            #5

            Hi, Ive tried running it and im getting absolutely nothing back. Ive updated the SQL as such for my table/data: declare @date as varchar(15) set @date = '2008-04-16' select * from tbl_QualityStandard where qs_Start >= convert(varchar(15),cast(@date as datetime),102) and qs_Start <= convert(varchar(15),(cast(@date as datetime)-365*2),102)

            B 1 Reply Last reply
            0
            • M munklefish

              Hi, Ive tried running it and im getting absolutely nothing back. Ive updated the SQL as such for my table/data: declare @date as varchar(15) set @date = '2008-04-16' select * from tbl_QualityStandard where qs_Start >= convert(varchar(15),cast(@date as datetime),102) and qs_Start <= convert(varchar(15),(cast(@date as datetime)-365*2),102)

              B Offline
              B Offline
              Blue_Boy
              wrote on last edited by
              #6

              do u have recoreded data in qs_Start column: qs_Start 2008-04-16 2008-04-15 2008-04-14 2008-04-13 or qs_Start 2008.04.16 2008.04.15 2008.04.14 2008.04.13 or write me how u have inserted data in qs_start column


              I Love T-SQL

              M 1 Reply Last reply
              0
              • B Blue_Boy

                do u have recoreded data in qs_Start column: qs_Start 2008-04-16 2008-04-15 2008-04-14 2008-04-13 or qs_Start 2008.04.16 2008.04.15 2008.04.14 2008.04.13 or write me how u have inserted data in qs_start column


                I Love T-SQL

                M Offline
                M Offline
                munklefish
                wrote on last edited by
                #7

                Hi, My date format is: 15/04/2008 eg day/month/year

                B 1 Reply Last reply
                0
                • M munklefish

                  Hi, My date format is: 15/04/2008 eg day/month/year

                  B Offline
                  B Offline
                  Blue_Boy
                  wrote on last edited by
                  #8

                  try this declare @date as varchar(15) set @date = '2008-04-16' select * from tbl_QualityStandard where qs_Start >= convert(varchar(15),cast(@date as datetime),103) and qs_Start <= convert(varchar(15),(cast(@date as datetime)-365*2),103)


                  I Love T-SQL

                  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