Announcement

Collapse
No announcement yet.

vb.net time & date

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    vb.net time & date

    I'm converting scripts to *.vb, but what's the proper syntax for time/date?
    In VBS, the command is:
    HTML Code:
    If Time<TimeSerial(17,00,00) and WeekdayName(Weekday(Now))<>"Saturday" then ...
    But in vb.net it just says Scipt compile error: Name 'Time' is not declared.on line 21

    #2
    You now need to prefix Time with DateTime like DateTime.now A quick google search turned up this for more examples:
    http://authors.aspalliance.com/aspxt...timeclass.aspx
    💁‍♂️ Support & Customer Service 🙋‍♂️ Sales Questions 🛒 Shop HomeSeer Products

    Comment


      #3
      Thanks Rupp - I tested a few of those, but with little success:
      hs.speak(datetime.dayofweek)
      hs.speak(datetime.time)
      hs.speak(datetime.date)
      hs.speak(datetime.timeofday)
      hs.speak(datetime.hour)
      These worked though:
      hs.speak(datetime.now)
      hs.speak(datetime.today)
      All I really need to do in this case is check to see if it's before 5:30PM and if it's a particular day. I looked around the net for a long time as well, but am not finding what I need.

      Comment


        #4
        Hia

        The reason you're hitting problems is because you need an instance of the datetime object to call some of those properties.

        Rather than datetime.dayofweek, you need...

        Now.DayOfWeek
        Now.Date
        Now.TimeOfDay
        Now.Hour

        Depending on the answer type that is returned you may also need to put .tostring on the end.

        e.g.

        Now.TimeOfDay.ToString()

        It's a personal choice but I use Visual Basic Developer Express Edition (free download) for writing vb.net code, and Visual Web Developer Express Edition for asp.net code.

        I find it's really useful becasue it makes it virtually impossible to get code like the above wrong (by highlighting errors and problems and also by providing intellisense so you can see what properties all the objects have)

        Anyway HTH

        Comment


          #5
          Try this...

          Code:
             		If Now.DayOfWeek <> DayOfWeek.Saturday Then
             			If Now.TimeOfDay.ToString < TimeValue("17:30:00") Then
             				' Do stuff here
             			End If
             		End If

          Comment


            #6
            If you are just converting VBScript to VB.net scripts just use:

            "TimeofDay" instead of "Time"
            "Today" instead of "Date"

            i.e

            hs.speak (TimeofDay)
            Jon

            Comment


              #7
              Awesome - Thanks guys, that should be a huge help!

              Comment

              Working...
              X