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!

Datetime to time 1

Status
Not open for further replies.

FoxWing

Programmer
Dec 20, 2004
44
GB
Hi,

Just a very simple question. How can i extract the TIME from a datetime variable ?


Thanks.
 
Chris

I beg to differ with your suggestion, but TIME() always returns the current time.

Foxwing

Code:
SET CENTURY ON 
Var1 = DATITME()
? SUBSTR(TTOC(var1),12,11)


Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Mike,

I agree with your general approach, but the result of the TTOC() will depend on current date setting. For example, if you have SET DATE LONG, you would get a different result than, say, SET DATE AMERICAN.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My sites:
Visual FoxPro (www.ml-consult.demon.co.uk)
Crystal Reports (www.ml-crystal.com)
 
Mike

Post in haste, repent at leisure.

You are correct as is your code - I misread the question to be 'How can i extract the TIME from datetime'
Code:
[COLOR=blue]SET CENTURY ON 
Var1 = DATETIME()
? RIGHT(TTOC(var1),11)[/color]
is another option

FAQ184-2483 - answering getting answered.​
Chris [pc2]
PDFcommandertm.net
PDFcommandertm.co.uk
 
Or, try:
Code:
var1=DATETIME()
? HOUR(var1)
? MINUTE(var1)
? SEC(var1)
note: don't use SECOND(var1) which will fail with "Too many arguments" because "SECOND" is just short for "SECONDS()" which takes no parameters, and returns the current time in seconds.

Also, try:
Code:
? TIME( SECONDS() )
which also shows 1/100's seconds. (though this has nothing to do with a datetime, if someone was using DATETIME() to get the current time, this could be helpful.)

- Bill

Get the best answers to your questions -- See FAQ481-4875.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top