Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...Thanks for a great forum. My problem was answered just by scrolling through previously solved problems. Great service!!..."

Geography

Where in the world do Tek-Tips members come from?
jezky82 (MIS)
6 Aug 12 2:36
sorry I am a beginner in vf, wondering how I would add to the data at the datetime variable. and change for example 06/08/12 01:33:58 PM to 06/08/12 05:33:58 PM
. thank you
Helpful Member!  MikeLewis (Programmer)
6 Aug 12 3:50
Hi Jesky,

Welcome to the forum.

I'm not completely sure what you want to do. In general, you use the DATETIME() function to set part or all of a datetime variable. The following might help:

(i) DATETIME() without any parameters returns the current datetime.

(ii) Call DATETIME() with up to six parameters to return a specific datetime. The parameters are for the year, month, day, hours, minutes and seconds respectively.

(ii) YEAR(), MONTH(), DAY(), HOUR(), MINUTE() and SEC() all return one element of a datetime.

(iv) When you add an integer to a datetime, you are adding that number of seconds.

So, to add five hours to a datetime (as per your question), you would simply add 18000 ( = 5 * 60 * 60) to it.

If that doesn't answer your question, perhaps you could explain in more detail what you are trying to do.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy

jezky82 (MIS)
6 Aug 12 3:53
how to make an automatic command to the terms, conditions, based on a datetime variable in foxpro. examples such as billing computer rental. rent a computer in 2 hours. after 2 hours of standby computer automatically can not be used anymore.
MikeLewis (Programmer)
6 Aug 12 3:54
So, are you saying you want to add two hours to a datetime?

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy

TeknoSoftInc (Programmer)
6 Aug 12 7:38
lnStart = seconds()

.. Do stuff

?seconds() - lnStart && gives u time elapsed in millisec

To get hrs, simply convert

Ali Koumaiha
TeknoSoft Inc.
Michigan

MikeLewis (Programmer)
6 Aug 12 7:48

Quote (Ali)

gives u time elapsed in millisec

Ahem. Not millisecs. Seconds.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy

TeknoSoftInc (Programmer)
6 Aug 12 8:40
Opps.. Sorry mike..

You're right..

Thanks for catching that

Thats what happens when you reply to a thread from ur phone before you even get out of bed...

Ali Koumaiha
TeknoSoft Inc.
Michigan

MikeLewis (Programmer)
6 Aug 12 8:58

Quote (Ali)

Thats what happens when you reply to a thread from ur phone before you even get out of bed..

My admiration reaches new bounds.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy

jezky82 (MIS)
6 Aug 12 9:45
can not with a direct example of such detail I will make running an automated process do the terms taken from a datetime filed out. 08/06/12 at 01:33:58 PM . thanks
jrbbldr (Programmer)
6 Aug 12 10:44
Using SECONDS() is good, but it is more challenging when the 2 times are in different days.

While I am still not clear on what you are wanting to do, here are a few examples of how you can work with VFP DateTime values

* --- Manually Create DateTime1 ---
SET HOURS TO 24
cTime1 = DTOC(DATE()) + ' ' + TIME()
tTime1 = CTOT(cTime1)
* --- Manually Create DateTime2 to be 2 Hours After tTime1---
tTime2 = tTime1 + 2*3600

Now you can work with the DateTime values

* -- Check If Current DateTime More Than 2 Hours From cTime1 --
SET HOURS TO 24
cCurrentDateTime = DTOC(DATE()) + ' ' + TIME()
tCurrentDateTime = CTOT(cCurrentDateTime)
IF (tCurrentDateTime - tTime1) >= (2 * 3600)
<do whatever>
ENDIF

* --- Test For One DateTime Greater Than Another DateTime ---
IF tTime1 > tTime2
<do whatever>
ENDIF

* --- Number of Seconds Between Two DateTimes ---
IF tTime2 - tTime1 < 20
<do whatever>
ENDIF

Good Luck,
JRB-Bldr

MikeLewis (Programmer)
6 Aug 12 10:54

Quote:

can not with a direct example of such detail I will make running an automated process do the terms taken from a datetime filed out. 08/06/12 at 01:33:58 PM .

Sorry, but I have no idea what this means.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy

MFGRIM (Programmer)
7 Aug 12 9:16
set hours to 24
ltDateTime = datetime(2012,08,06,13,33,58)

ltDateTimeNow = DateTime()

lnNumHours = 2

if ltDateTimeNow - ltDateTime = (lnNumHours *60*60) **Take Hours Multiple by Minutes in an hour, and seconds in a minute)

<do your code>

endif

***

Not sure if this is what you looking for, but if you pass the datetime in, you can parse it out to get all the varibles you need for the ltDateTime



jezky82 (MIS)
7 Aug 12 10:46
may be more details like this. I want to make computer rental. at the cashier's no way to order payment of usage time. like how long people use computers. example there is a lease 2 hours. I live 2 hours of data input and after 2 hours the computer will be locked, I've been able to make a computer that is in the lease is locked with one command. but how to program the automatic teller after 2 hours of run commands that are provided to lock my computer in the lease. I've got datatime after 2 hours was calculated from the initial usage. but how to use it datatime weeks to trigger the commands used to lock the computer. thank you
jrbbldr (Programmer)
7 Aug 12 11:00
'Lock the computer'

How do you want to 'Lock' the computer?
* Lock out additional Keyboard use?
* Do a Re-boot of the computer?
(This is not actually a 'lock', but it does stop what was being done.)

There are off-the-shelf commercial programs that can 'Lock' a computer. Maybe you just want to use one of those or have your VFP application launch them.

You can do a Google search for:
pc use lock
or
pc use keyboard lock
and you will find a number of tools to 'lock' a computer.

If you merely wanted to throw a user out of the workstation you could, from your VFP application, do a ShellExecute() and launch the DOS Shutdown.exe

Good Luck,
JRB-Bldr




MikeLewis (Programmer)
7 Aug 12 11:11
Jezky,

You have had lots of useful suggestions for how to deal with datetimes. You have given no indication of whether or not they were useful. Right now, it's hard to know exactly what you need, or whether we have answered your original question.

Please don't take offence at this. I know it can be difficult to explain things in English if that is not your native language. If that's the case, I suggest you find a friend who has good English to translate your question. We will then do our best to help you find the answer.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy

jezky82 (MIS)
7 Aug 12 11:12
jrbbldr thanks, but what i need and i meant above is not the way to lock it but how to run a time-based process that has been stored in datatime filed. ie just by sending a file to computer off.txt hired through a network i've been able to lock the computer. but how to run a command foxpro program file off.txt delivery time schedule stored in the database datetime filed kas.dbf. thanks you
jezky82 (MIS)
7 Aug 12 11:30
jrbbldr what if i write this,i save time finish datetime () in the database pc1 fields out
i=datatime()
use pc1
i=out
if datatime()>i
do
endif

'whether the command will do the work in accordance datatime stored in the fields out'
jezky82 (MIS)
7 Aug 12 11:33
or
i1=datatime()
i2=datatime()
use pc1
i1=out
if i2>i
do
endif
jrbbldr (Programmer)
7 Aug 12 11:58
Note - unless you have written a Function yourself, there is no datatime() function in VFP

I already gave you some examples above that you might be able to use with some slight modifications.

CODE -->

SET HOURS TO 24

* -- Check If Current DateTime More Than OUT Time --
tOutDateTime = <get this DateTime value from somewhere - possibly a value entered into a server data table through a internet cafe 'management' workstation>

cCurrentDateTime = DTOC(DATE()) + ' ' + TIME()
tCurrentDateTime = CTOT(cCurrentDateTime)
IF tCurrentDateTime >= tOutDateTime
   <do whatever you need to do>
ENDIF 

If this won't work for you, then I am still VERY unclear as to what you need to do.

Good Luck,
JRB-Bldr
jezky82 (MIS)
7 Aug 12 12:23
jrbbldr thanks. now just how to write procedures that you always read over and over again, or continuously by the program so that when the time is right or appropriate then do the command will run
jrbbldr (Programmer)
7 Aug 12 13:08
There are a variety of ways to 'execute over and over again' depending on the precision you need and the general approach you take.

One of the easiest ways is to compile your VFP application into an EXE and then use Windows Scheduled Task to run it periodically. Only you will be able to determine if the precision of the timing is acceptable to you.

Other ways include running your VFP application full-time in the background and having it periodically check on the time. Here too there are variations as to how that can be accomplished and that depends on how you architect your application.

Good Luck,
JRB-Bldr


jrbbldr (Programmer)
8 Aug 12 15:40
While we all want to encourage using VFP for application development, it still seems like you might be trying to "Re-invent the Wheel" (that is - trying to create something that is already created and working in the world)

Have you done a Google search for:
internet cafe software manage

It might be worth you while to look into these software packages.

Good Luck,
JRB-Bldr
jezky82 (MIS)
9 Aug 12 10:35
thank you all for helping me finally solved my problem.
Special thanks to jrbbldr patient wants to help me.

_screen.Caption="AUTO"
WOUT1=DATETIME()
WOUT2=DATETIME()
WOUT3=DATETIME()
WOUT4=DATETIME()
WOUT5=DATETIME()
WOUT6=DATETIME()

DO WHILE .T.
NOWTIME=DATETIME()
OPEN DATABASE c:\data1.dbc SHARED
USE c:\room.dbf SHARED
WOUT1=OUT1
WOUT2=OUT2
WOUT3=OUT3
WOUT4=OUT4
WOUT5=OUT5
WOUT6=OUT6
USE
IF NOWTIME=WOUT1
do offpc1
ENDIF
IF NOWTIME=WOUT2
do offpc2
ENDIF
IF NOWTIME=WOUT3
do offpc3
ENDIF
IF NOWTIME=WOUT4
do offpc4
ENDIF
IF NOWTIME=WOUT5
do offpc5
ENDIF
IF NOWTIME=WOUT6
do offpc6
ENDIF
ENDDO
jrbbldr (Programmer)
9 Aug 12 11:40
Unless there is more code somewhere that you have not listed above, it looks like you will either shut down ALL PC's or NONE of the PC's everytime the application runs.

I think that you have the basic understanding of how to use the DATETIME() values, but you need to put some thought into how you are going to architect your application so that you get what you want.

You might possibly want 2 separate VFP applications.
1. A managerial EXE where the Shutdown DateTime values for each individual Workstation are entered into the Room data table.

2. An application which runs automatically from the Windows Scheduled Tasks utility and which analyses the current DateTime values against the previously entered Room data table values and Shuts down the PC's or not.

Good Luck,
JRB-Bldr
OlafDoschke (Programmer)
9 Aug 12 12:21
If running scheduled tasks, the idea would be to set them up programmatically to run at a certain time for powering a pc on or off, the only code the exe itself would need therefor is to either shut a pc on or off, the time checking is done by the taskscheduler, not by your app anymore.

Eg poweron.exe would expect a PC name or IP or NIC MAC address or whatever it takes to turn on a certain pc and poweroff.exe would take the same type of parameter to turn a pc off. Or make it two parameters pc and "on" or "off" to pass into some poweronoff.exe, whatever.

The logic tu run an app at a certain time and then check if that is the current time is bound to fail, because it will never exactly start at a predefined time. You would always need to check for the planned time being passed already. Startup of an exe is a thing taking up to a few seconds, also taskscheduler isn't precisely starting at a planned time. That inexactness shouldn't matter though, as you talk about hours a pc is rented and kept ON.

You won't need to cope with time calculation and comparison, that part of the task would be taken care of by the OS and the taskscheduler system.

Do you get the idea now? You don't need anything more or less then to do the action planned for that time in the exe the scheduled task calls.

Bye, Olaf.
jrbbldr (Programmer)
9 Aug 12 16:57
Based on the code you wrote above, one thing I am still not sure you fully understand is how to determine the DateTime value for some time other than NOW.

You might want to look at:
How To Add or Subtract Time with a DateTime Data Type
http://support.microsoft.com/kb/176043

Good Luck,
JRB-Bldr

OlafDoschke (Programmer)
9 Aug 12 18:10
creating a scheduled task.

http://doughennig.blogspot.de/2007/04/scheduling-t...

It will run at ther predefined time. So here you put in the planned time.

You won't need to check whether a predefined time has arrived in the called exe, it is called at (about) that time. Not earlier, just with a few seconds lag.

And the to shut down a pc you can use this code:
http://www.news2news.com/vfp/?example=122&func...

But there is no way to power up a pc not running I know of.

This is just a minimal part of the problems an internet cafe software has to solve. Plus you will rather just lock a pc after the rented time and not shut it off.

Overall, I still recommend you look out for an already existing solution.

Bye, Olaf.
Helpful Member!  jrbbldr (Programmer)
9 Aug 12 19:49
Another way that I have used to force the Shutdown of a PC is:

CODE -->

tcEXEFile = "C:\Windows\System32\Shutdown.exe"
tcParameters = "-s -t 1 -f"
tcCmd = "Open"
tcCmd = PROPER(m.tcCmd)

* --- API Call to communicate with an application based on the registered file-type. ---
DECLARE INTEGER ShellExecute ;
   IN SHELL32.DLL ;
   INTEGER nWinHandle,;
   STRING cOperation,;
   STRING cFileName,;
   STRING cParameters,;
   STRING cDirectory,;
   INTEGER nShowWindow

IF FILE(tcEXEFile)
   * --- If Old DOS Shutdown Exists, Run It To Shutdown Workstation ---
   lnFileStatus = ShellExecute(0,"&tcCmd",tcEXEFile,tcParameters,"",1)
ENDIF 

Good Luck,
JRB-Bldr



MikeLewis (Programmer)
10 Aug 12 3:42

Quote:

CODE -->

tcEXEFile = "C:\Windows\System32\Shutdown.exe" 

Except that, rather than hard-code the path, I would use SHGetSpecialFolderLocation() to locate the file.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips, training, consultancy

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close