Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

add datetime variable 2

Status
Not open for further replies.

jezky82

MIS
Jul 7, 2012
39
0
0
ID
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
 
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
 
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.
 
lnStart = seconds()

.. Do stuff

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

To get hrs, simply convert

Ali Koumaiha
TeknoSoft Inc.
Michigan
 
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
 
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
 
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

 
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
 
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



 
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
 
'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




 
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
 
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
 
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'
 
or
i1=datatime()
i2=datatime()
use pc1
i1=out
if i2>i
do
endif
 
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
 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top