Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
DATE$ function
#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


Messages In This Thread
DATE$ function - by eoredson - 10-04-2023, 05:31 AM
RE: DATE$ function - by mnrvovrfc - 10-04-2023, 07:11 AM
RE: DATE$ function - by SpriggsySpriggs - 10-04-2023, 11:19 AM
RE: DATE$ function - by SMcNeill - 10-04-2023, 11:27 AM
RE: DATE$ function - by TempodiBasic - 10-04-2023, 05:04 PM
RE: DATE$ function - by bplus - 10-04-2023, 05:34 PM
RE: DATE$ function - by RhoSigma - 10-04-2023, 06:23 PM
RE: DATE$ function - by Kernelpanic - 10-04-2023, 07:23 PM
RE: DATE$ function - by eoredson - 10-04-2023, 10:24 PM
RE: DATE$ function - by SMcNeill - 10-04-2023, 10:36 PM
RE: DATE$ function - by TerryRitchie - 10-04-2023, 10:51 PM
RE: DATE$ function - by eoredson - 10-04-2023, 10:52 PM
RE: DATE$ function - by eoredson - 10-04-2023, 11:10 PM
RE: DATE$ function - by eoredson - 10-05-2023, 01:49 AM
RE: DATE$ function - by SpriggsySpriggs - 10-05-2023, 11:11 AM
RE: DATE$ function - by eoredson - 10-06-2023, 12:57 AM
RE: DATE$ function - by SpriggsySpriggs - 10-06-2023, 02:10 AM
RE: DATE$ function - by eoredson - 10-06-2023, 02:22 AM
RE: DATE$ function - by SpriggsySpriggs - 10-06-2023, 02:58 AM
RE: DATE$ function - by eoredson - 10-06-2023, 04:33 AM
RE: DATE$ function - by eoredson - 10-06-2023, 03:43 AM
RE: DATE$ function - by SpriggsySpriggs - 10-06-2023, 12:26 PM
RE: DATE$ function - by eoredson - 10-07-2023, 05:01 AM
RE: DATE$ function - by SpriggsySpriggs - 10-07-2023, 01:49 PM
RE: DATE$ function - by mnrvovrfc - 10-07-2023, 05:03 AM
RE: DATE$ function - by eoredson - 10-08-2023, 10:21 PM
RE: DATE$ function - by eoredson - 10-11-2023, 04:25 AM
RE: DATE$ function - by SpriggsySpriggs - 10-12-2023, 03:14 AM
RE: DATE$ function - by eoredson - 10-12-2023, 11:25 PM
RE: DATE$ function - by SMcNeill - 10-12-2023, 11:37 PM
RE: DATE$ function - by eoredson - 10-13-2023, 12:46 AM
RE: DATE$ function - by eoredson - 10-19-2023, 01:35 AM
RE: DATE$ function - by eoredson - 10-21-2023, 03:15 AM
RE: DATE$ function - by SMcNeill - 10-21-2023, 04:17 AM
RE: DATE$ function - by eoredson - 10-21-2023, 05:52 AM
RE: DATE$ function - by SpriggsySpriggs - 10-21-2023, 04:07 AM
RE: DATE$ function - by SpriggsySpriggs - 10-21-2023, 06:50 AM
RE: DATE$ function - by eoredson - 10-23-2023, 01:29 AM
RE: DATE$ function - by SMcNeill - 10-23-2023, 01:40 AM
RE: DATE$ function - by SpriggsySpriggs - 10-23-2023, 11:55 AM
RE: DATE$ function - by eoredson - 10-24-2023, 01:49 AM
RE: DATE$ function - by SMcNeill - 10-24-2023, 02:32 AM
RE: DATE$ function - by SMcNeill - 10-24-2023, 02:36 AM
RE: DATE$ function - by eoredson - 10-25-2023, 02:40 AM
RE: DATE$ function - by mnrvovrfc - 10-25-2023, 03:43 AM
RE: DATE$ function - by eoredson - 10-25-2023, 04:00 AM
RE: DATE$ function - by SpriggsySpriggs - 10-25-2023, 12:13 PM
RE: DATE$ function - by eoredson - 10-25-2023, 11:53 PM
RE: DATE$ function - by Kernelpanic - 10-26-2023, 12:27 AM
RE: DATE$ function - by PhilOfPerth - 10-26-2023, 02:49 AM
RE: DATE$ function - by eoredson - 10-26-2023, 02:30 AM
RE: DATE$ function - by eoredson - 10-27-2023, 11:04 PM
RE: DATE$ function - by SMcNeill - 10-27-2023, 11:23 PM
RE: DATE$ function - by eoredson - 10-27-2023, 11:29 PM
RE: DATE$ function - by SMcNeill - 10-28-2023, 12:09 AM
RE: DATE$ function - by eoredson - 10-28-2023, 12:24 AM



Users browsing this thread: 13 Guest(s)