Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
DATE$ function
#1
I noticed the Date$ function returns the current date, but there is no:

Code: (Select All)
  Print "Date";
  Input D$
  Date$ = D$
why would that be!?

I would like to be able to set the system date.

Erik.
Reply
#2
(10-04-2023, 05:31 AM)eoredson Wrote: I would like to be able to set the system date.

It's not allowed on Linux, nor set the `TIME$` from QB64. It would require temporary superuser permission.

I guess the command versions were a trick that worked very well on 16-bit computers running GW-BASIC or BASICA. But it became dangerous to allow the user to change the date and time from a program. Even though Windows10 and earlier never resisted the user setting the time completely wrong. Probably Windows11 has become line Linux. Some operating systems don't handle time zone correctly. They don't allow NTP sync which is otherwise a solution for improperly setting the time according to time zone related to UTC. On one distro I have to run a separate program for NTP sync because, for some reason, the GUI system settings for that operating system keeps the whole dialog greyed out. I cannot even manually set the date and time.

I noticed something else, LOL you're trying to use `INPUT` to obtain a date! You will have to check the input rigidly. There are a wide variety of date formats. What if the user wants to type in a day of the week, but it's wrong for the given date? "Tuesday October 4 2023"? It could be dangerous to accept that. (Today is Wednesday.) If you look at the help for `strftime()` function in C, you would notice there are mind-boggling combinations of displaying items from the date, time or time zone.
Reply
#3
If you want to set the system date, I recommend clicking the date in the bottom right corner of your monitor and changing it through the popup. In Control Panel, this requires administrator privileges. In Windows' new Settings menu, this can be done without those rights and does the exact same thing. Changing the date and time through some program would be a bad idea, as mnrvovrfc (is that just some random letter combination?) said.
Tread on those who tread on you

Reply
#4
(10-04-2023, 11:19 AM)SpriggsySpriggs Wrote: If you want to set the system date, I recommend clicking the date in the bottom right corner of your monitor and changing it through the popup. In Control Panel, this requires administrator privileges. In Windows' new Settings menu, this can be done without those rights and does the exact same thing. Changing the date and time through some program would be a bad idea, as mnrvovrfc (is that just some random letter combination?) said.

Isn't it:   men are vov-riffic? (mn r vov rfc)

The vov is symbolic... leave your elbows down, raise your hands up and out to the side, and make a piteous face like you're surrendering or clueless.

At least, that's the interpretation I take away from it.  Did I win?  Was I right?? Men are shrug-riffic?
Reply
#5
@eoredson

the strange matter is that parser lets you type "Date$ = "something"  OR "Date$= MyString$" without a warning or an error alert!

As Wiki shows Date$ is a function that returns a string value... it cannot be used as a string variable to initialize!

Date$ wiki
Reply
#6
(10-04-2023, 05:04 PM)TempodiBasic Wrote: @eoredson

the strange matter is that parser lets you type "Date$ = "something"  OR "Date$= MyString$" without a warning or an error alert!

As Wiki shows Date$ is a function that returns a string value... it cannot be used as a string variable to initialize!

Date$ wiki

He's stuck in the past and wants to do all you coulda done with old QB. You use to be able to set date as he has shown.

Hey Eric does it work from a .bat file?
b = b + ...
Reply
#7
(10-04-2023, 05:34 PM)bplus Wrote:
(10-04-2023, 05:04 PM)TempodiBasic Wrote: @eoredson

the strange matter is that parser lets you type "Date$ = "something"  OR "Date$= MyString$" without a warning or an error alert!

As Wiki shows Date$ is a function that returns a string value... it cannot be used as a string variable to initialize!

Date$ wiki

He's stuck in the past and wants to do all you coulda done with old QB. You use to be able to set date as he has shown.

Hey Eric does it work from a .bat file?

Also this Unsupported keywords Wiki page states alraedy in the first few lines why it don't give an error. Clear advantage for people who are willing to look around by themself instead of complaining over and over.
Reply
#8
Quote:Also this Unsupported keywords Wiki page states alraedy in the first few lines why it don't give an error.
DATE$ (statement) The statement is not supported.

And I was wondering why this doesn't work, i.e. the date isn't changed.  Blush

Code: (Select All)

Dim As String heutigesDatum

Print "Heute ist "; Date$
heutigesDatum = Date$

Date$ = "11-21-1992"
Print Date$
Date$ = heutigesDatum
Reply
#9
I tried the following code with no result:

Code: (Select All)
' some code to attempt to change the system date.
' returns error:
'   a required privilege is not held by the client.
DefLng A-Z

Type SYSTEMTIME
   wYear As Integer
   wMonth As Integer
   wDayOfWeek As Integer
   wDay As Integer
   wHour As Integer
   wMinute As Integer
   wSecond As Integer
   wMilliseconds As Integer
End Type

Declare Dynamic Library "kernel32"
   Function GetLocalTime& (lpSystemTime As SYSTEMTIME)
   Function SetLocalTime& (lpSystemTime As SYSTEMTIME)
   Function GetSystemTime& (lpSystemTime As SYSTEMTIME)
   Function SetSystemTime& (lpSystemTime As SYSTEMTIME)
   Function GetLastError& ()
   Function FormatMessageA& (ByVal f As Long, f$, Byval e As Long, Byval d As Long, g$, Byval s As Long, h$)
End Declare

Dim Shared SysTime As SYSTEMTIME
Dim Shared ErrorBuffer As String * 260

Print "Current date: "; Date$
Print "Enter date(mm-dd-yyyy)";
Input z$
z$ = LTrim$(RTrim$(z$))
If Len(z$) Then
   z = ValidDate(z$)
   If z Then
      ' mm-dd-yyyy
      x = GetLocalTime(SysTime)
      SysTime.wMonth = Int(Val(Left$(z$, 2)))
      SysTime.wDay = Int(Val(Mid$(z$, 4, 2)))
      SysTime.wYear = Int(Val(Right$(z$, 4)))
      x = SetLocalTime(SysTime)
      If x = 0 Then
         Print "Error Date reset: "; z$
         Print DisplayWinError$(x)
      Else
         Print "Date reset to: "; z$
      End If
   Else
      Print "Invalid date."
   End If
End If
End

Function ValidDate (Var$)
   ' mm-dd-yyyy
   Var$ = RTrim$(Var$)
   If Len(Var$) <> 10 Then
      ValidDate = False
      Exit Function
   End If
   For Var = 1 To 10
      V$ = Mid$(Var$, Var, 1)
      Select Case Var
         Case 1, 2, 4, 5, 7, 8, 9, 10
            If V$ >= "0" And V$ <= "9" Then
               Eat$ = ""
            Else
               ValidDate = False
               Exit Function
            End If
         Case Else
            If V$ <> "-" Then
               ValidDate = False
               Exit Function
            End If
      End Select
   Next
   M = Int(Val(Mid$(Var$, 1, 2)))
   D = Int(Val(Mid$(Var$, 4, 2)))
   Y = Int(Val(Mid$(Var$, 7, 4)))
   If M >= 1 And M <= 12 Then
      If D >= 1 And D <= 31 Then
         If Y >= 1980 And Y <= 2079 Then
            L = 0
            If Y / 4 = Y \ 4 Then
               L = -1
            End If
            If Y / 100 = Y \ 100 Then
               L = 0
            End If
            If Y / 400 = Y \ 400 Then
               L = -1
            End If
            Select Case M
               Case 1, 3, 5, 7, 8, 10, 12
                  If D <= 31 Then
                     ValidDate = -1
                     Exit Function
                  End If
               Case 4, 6, 9, 11
                  If D <= 30 Then
                     ValidDate = -1
                     Exit Function
                  End If
               Case 2
                  If L Then
                     If D <= 29 Then
                        ValidDate = -1
                        Exit Function
                     End If
                  End If
                  If D <= 28 Then
                     ValidDate = -1
                     Exit Function
                  End If
            End Select
         End If
      End If
   End If
   ValidDate = 0
End Function

' display windows error message
Function DisplayWinError$ (x)
   ' define error message value
   v& = GetLastError
   ' call windows error message routine
   x& = FormatMessageA&(&H1200, "", v&, 0, ErrorBuffer$, 260, "")
   If x& Then
      DisplayWinError$ = Left$(ErrorBuffer$, x& - 2)
   Else
      DisplayWinError$ = "Unknown error 0x" + Hex$(v&) + "."
   End If
   x = -1
End Function
Reply
#10
Did you try "Run as admin"?  Windows really doesn't want folks to do much tinkering on date and time anymore, as they like to sync things all nice and neat via the web.  I honestly can't think of the last time that I've ever had to manually set the date and time on any of my PCs.
Reply




Users browsing this thread: 11 Guest(s)