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. Compare dates

Compare dates

Scheduled Pinned Locked Moved C#
database
2 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
    Mamphekgo
    wrote on last edited by
    #1

    Hi.i am trying to compare today 's date with a date from database.if it found like today 's date is available from database it should return something like eventname.here is my code string Today = DateTime.Now.ToShortTimeString().ToString(); SqlCommand cmdDisplay = new SqlCommand(); cmdDisplay.Connection = conn; cmdDisplay.CommandText = "SELECT EventName FROM Events WHERE EventDate = '"+ Today + "'"; SqlDataReader dr = cmdDisplay.ExecuteReader(); while(dr.Read()) { string EDate; EDate = dr["EventDate"].ToString(); if(EDate == Today) { txtEventName.Text =dr["EventName"].ToString(); } }

    C 1 Reply Last reply
    0
    • M Mamphekgo

      Hi.i am trying to compare today 's date with a date from database.if it found like today 's date is available from database it should return something like eventname.here is my code string Today = DateTime.Now.ToShortTimeString().ToString(); SqlCommand cmdDisplay = new SqlCommand(); cmdDisplay.Connection = conn; cmdDisplay.CommandText = "SELECT EventName FROM Events WHERE EventDate = '"+ Today + "'"; SqlDataReader dr = cmdDisplay.ExecuteReader(); while(dr.Read()) { string EDate; EDate = dr["EventDate"].ToString(); if(EDate == Today) { txtEventName.Text =dr["EventName"].ToString(); } }

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      You're storing dates as strings in the ShortTimeString format ? That's a time, not a date. And, it's an inefficient way to store them. And it's redundant - you ask for only for values with a specific time, and then you check to make sure your database is not lying to you ? I don't see a question here - what is the problem ?

      Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

      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