SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Evangelist
    Join Date
    Jun 2004
    Location
    ny
    Posts
    560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question datetime vb.net issues

    I am trying to check if current datetime is between current date plus 06:00:00 and 20:00:00 (in turkish culture)
    I want date to be populated as "dd.mm.yyyy hh:mm:ss"... How would I do this in vb.net?

    Dim sDate as String = TodayIs.ToShortDateString + " 06:00:00"
    Dim eDate as String = TodayIs.ToShortDateString + " 20:00:00"

    if time >= sDate and time <= eDate then
    ....

  2. #2
    SitePoint Guru Jason__C's Avatar
    Join Date
    Oct 2009
    Location
    Racoon City
    Posts
    660
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Ever thought of changing the culture before formatting the Date?
    Chuck Norris is so tough,
    mosquitos ask for permission before they bite him

  3. #3
    SitePoint Author silver trophybronze trophy
    wwb_99's Avatar
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    10,629
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    Don't go out to strings. If you are looking to see if something is between 6am and 8pm then:

    Code:
    Dim today as DateTime.Now
    Dim sixAm as today.Date.AddHours(6)
    Dim eightPm as today.Date.AddHours(20)
    Then you can check if something is between those two dates. Strings are not your friends.

  4. #4
    SitePoint Evangelist
    Join Date
    Jun 2004
    Location
    ny
    Posts
    560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Jason__C View Post
    Ever thought of changing the culture before formatting the Date?

    That code gives an error of "Not valid as identifier."

  5. #5
    SitePoint Guru Jason__C's Avatar
    Join Date
    Oct 2009
    Location
    Racoon City
    Posts
    660
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Can you show me the code for the culture change you made?
    Chuck Norris is so tough,
    mosquitos ask for permission before they bite him


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •