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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with Time()

Status
Not open for further replies.

Serincino

Programmer
Jun 13, 2003
61
US
I have a form that needs a time stamp form since this form will be used to print a ticket. When the form loads and refreshs thisform.mytextbox.value = Time() is run. This places the time in the textbox, but the time is in military time. I've tried using set time to 12 but this still does not effect the time that displays. I'm looking to get a time in the format of HH:MM AM/PM to display. Does anyone know of a method that does this without having ot write me own?
thanks,

Serincino
 
Sorry, Charlie.

VFP's own help says that time() returns the time in 24 hour format and makes no apologies for it.

This could even work in your favor, if you think about it:
You can store the 24 hour times as stamps in your table(s) for use in comparing for reporting/querying.

Just write a function to display it in whatever fashion you wish on the client side after the calls.
 
cut and paste the following in to a prg called ampm


function ampm
rvalue=''
thetime=VAL(CHRTRAN(TIME(),':',''))
IF thetime>120000
theampm="PM"
thetime=thetime-120000
thetime=LEFT(PADL(ALLTRIM(STR(thetime)),6,'0'),4)
rvalue=LEFT(thetime,2)+':'+RIGHT(thetime,2)+theampm
ELSE
theampm="AM"
thetime=LEFT(PADL(ALLTRIM(STR(thetime)),6,'0'),4)
rvalue=LEFT(thetime,2)+':'+RIGHT(thetime,2)+theampm
ENDIF

RETURN (rvalue)


then use: ampm() instead of time()


Steve Bowman
steve.bowman@ultraex.com

 
Minor adjustment

cut and paste the following in to a prg called ampm


function ampm
rvalue=''
thetime=VAL(CHRTRAN(TIME(),':',''))
IF thetime>120000
theampm="PM"
thetime=thetime-120000
thetime=LEFT(PADL(ALLTRIM(STR(thetime)),6,'0'),4)
rvalue=LEFT(thetime,2)+':'+RIGHT(thetime,2)+' '+theampm
ELSE
theampm="AM"
thetime=LEFT(PADL(ALLTRIM(STR(thetime)),6,'0'),4)
rvalue=LEFT(thetime,2)+':'+RIGHT(thetime,2)+' '+theampm
ENDIF

RETURN (rvalue)


then use: ampm() instead of time()

forgot the space between the time and AM/PM

"10:00AM" now "10:00 AM"

Steve Bowman
steve.bowman@ultraex.com

 
Serincino,

How about a one-liner to get what you need? Instead of Time() use the following:

TTOC(DATETIME(),2)

...To display or hide seconds you can SET SECONDS ON/OFF

Slighthaze = NULL

[ul][li]FAQ184-2483
An excellent guide to getting a fast and accurate response to your questions in this forum.[/li][/ul]
 
You could also use


set hour to 12
cCurrentTime=RIGHT(TTOC(DATETIME()),11)


this however includes seconds


Steve Bowman
steve.bowman@ultraex.com

 
I must be to quick to create UDF and to SLOW to read the documentation. In the years of using TTOC I never knew it had parameters

Steve Bowman
steve.bowman@ultraex.com

 
Just a question.
Why would you want to use the extrat function call RIGHT() in your code: RIGHT(TTOC(DATETIME()),11)

When TTOC(DATETIME(),2) returns the RIGHT(11) characters of DATETIME() anyway?


-Dave S.-
[cheers]
Even more Fox stuff at:
 
Read above ^, DUH I feel dumb enough already

Steve Bowman
steve.bowman@ultraex.com

 
steveb7,

I know it, I can't tell you the number of times that has happened to me here since joining Tek-Tips... Someone will post a simple solution to a problem, and I think wow I never knew you could do that! We're all definately learning here and that is of course the important thing.

Slighthaze = NULL

[ul][li]FAQ184-2483
An excellent guide to getting a fast and accurate response to your questions in this forum.[/li][/ul]
 
rob444

There is a problem with your suggestion...if Set Seconds Off then it won't work as expected.

You would have to do something like this...

?iif(Set("seconds") = "OFF",TTOC(DATETIME(),2), STUFF(TTOC(DATETIME(),2),6, 3, ''))

...with this modification your suggestion does yield a solution that is independent of the Seconds setting.

Slighthaze = NULL

[ul][li]FAQ184-2483
An excellent guide to getting a fast and accurate response to your questions in this forum.[/li][/ul]
 
THANK YOU SO MUCH!!!! I was out of the office for a couple of days since the post. I never expected such a question to raise such conversation. Thank you all SO much!

-Serincino
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top