Highlighted
Absent Member.
Absent Member.
355 views

[archive] System Date

[Migrated content. Thread originally posted on 02 September 2009]

Hello,
Just a quick question:
Is it possible to change the system date programmatically?

Thanks
0 Likes
5 Replies
Highlighted
Absent Member.
Absent Member.

RE: [archive] System Date

use good old dos 🙂
DATE

in german its date tt-mm-yy
think that the order in other language could be yy-mm-tt...

here an example:
call "C$SYSTEM" using "date 03-09-09", 97 end-call.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] System Date

I used the following code and it failed with a date-status of 5.
Does anyone know what error 5 means?

01 Archive-date pic x(13) value "Date 01-02-09".
01 date-status pic 9 value 0.

call "C$system" using Archive-date, "8"
giving date-status.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] System Date

if this list is correct:
http://heim.ifi.uio.no/~stanisls/helppc/dos_error_codes.html

05 Access denied
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] System Date

If this is Windows, you can use the API function SetSystemTime.

Info: http://msdn.microsoft.com/en-us/library/ms724942(VS.85).aspx

The structure in question:

[FONT=Courier New]typedef struct _SYSTEMTIME {[/FONT]
[FONT=Courier New]WORD wYear;[/FONT]
[FONT=Courier New]WORD wMonth;[/FONT]
[FONT=Courier New]WORD wDayOfWeek;[/FONT]
[FONT=Courier New]WORD wDay;[/FONT]
[FONT=Courier New]WORD wHour;[/FONT]
[FONT=Courier New]WORD wMinute;[/FONT]
[FONT=Courier New]WORD wSecond;[/FONT]
[FONT=Courier New]WORD wMilliseconds;[/FONT]
[FONT=Courier New]}SYSTEMTIME, *PSYSTEMTIME;[/FONT]

Can be translated like this:

[FONT=Courier New]01 SYSTEMTIME.[/FONT]
[FONT=Courier New]  03 wYear            PIC 9(4) COMP-N.[/FONT]
[FONT=Courier New]  03 wMonth           PIC 9(4) COMP-N.[/FONT]
[FONT=Courier New]  03 wDayOfWeek       PIC 9(4) COMP-N.[/FONT]
[FONT=Courier New]  03 wDay             PIC 9(4) COMP-N.[/FONT]
[FONT=Courier New]  03 wHour            PIC 9(4) COMP-N.[/FONT]
[FONT=Courier New]  03 wMinute          PIC 9(4) COMP-N.[/FONT]
[FONT=Courier New]  03 wSecond          PIC 9(4) COMP-N.[/FONT]
[FONT=Courier New]  03 wMilliseconds    PIC 9(4) COMP-N.[/FONT]

Use it like this:

[FONT=Courier New]*Load library[/FONT]
[FONT=Courier New]CALL "Kernel32.dll"[/FONT]
[FONT=Courier New]*Set values of SYSTEMTIME group[/FONT]
[FONT=Courier New]*Call function[/FONT]
[FONT=Courier New]CALL "SetSystemTime@WINAPI" USING BY REFERENCE SYSTEMTIME[/FONT]

However, generally speaking, it is not a good idea that applications change the system time. Also do note that with Vista and Windows 7, there are security constraints.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] System Date

Thanks for your help.
What I ended up doing was using c$system to run a .bat file with the dos date command in it.
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.