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. if(DateTime.Now>=OldDateTime)..????

if(DateTime.Now>=OldDateTime)..????

Scheduled Pinned Locked Moved C#
questiondatabase
3 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.
  • A Offline
    A Offline
    Adel83k
    wrote on last edited by
    #1

    how can i do something like If (DateTime.Now >= StoredDateTime) ??? i extract the StoredDateTime from database which is save in earlier time useing DateTime.Now.ToString(); I don't know the setting of time in the machine so i can't expect the returned format .... so how can i accomplish this task.. ADEL K Khalil

    C D 2 Replies Last reply
    0
    • A Adel83k

      how can i do something like If (DateTime.Now >= StoredDateTime) ??? i extract the StoredDateTime from database which is save in earlier time useing DateTime.Now.ToString(); I don't know the setting of time in the machine so i can't expect the returned format .... so how can i accomplish this task.. ADEL K Khalil

      C Offline
      C Offline
      ChrisAdams
      wrote on last edited by
      #2

      Why are you converting the DateTime to a string. Why not keep it as instance of a DateTime object, you can then use the compare method. Also, use DateTime.UtcNow, instead of Now - this will ensure that your time is always stored using the same timezone. It's should be quite easy to convert it back to the user's timezone for display purposes. If your stuck saving it as a string to the database, then you should be able to use the string format objects to control the format it is saved as.

      1 Reply Last reply
      0
      • A Adel83k

        how can i do something like If (DateTime.Now >= StoredDateTime) ??? i extract the StoredDateTime from database which is save in earlier time useing DateTime.Now.ToString(); I don't know the setting of time in the machine so i can't expect the returned format .... so how can i accomplish this task.. ADEL K Khalil

        D Offline
        D Offline
        DougW48
        wrote on last edited by
        #3

        Chris is right, try to make the structure in your database hold a DateTime object and not a string. If you try to query the database for dates using comparisons other than equals, you'll get unexpected results since it'll be returning rows based on the STRING value of the datetime, not the actual datetime. Good luck!

        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