# How to Use secondsFromTime() and secondsTillTime() Functions

#### CHOZEN

##### New member
2019 Donor
I want to utilize SecondsFromTime and SecondsTillTime in thinkscript to write a code to place in my scanner that will only scan premarket from 4am - 9:30 am.

Found this example:

Code:
``````# The following statement will be true any time AFTER 9:30 am
def Aftr930 = secondsFromTime(930) > 0;``````

Solution
Search code here that uses SecondsFromTime and SecondsTillTime. You may need to adjust for your timezone.

I use a variable in all my scripts like

Code:
``input timeOffsetFromEST = -300; #hint timeOffsetFromEST: 24-hour time offset from EST (-300 for PST)``

and then

Code:
``````startTime = 0630 - timeOffsetFromEST;

and then maybe something like

Code:
``````def isActive = if SecondsTillTime(endTime) > 0 and SecondsFromTime(startTime) >= 0
then 1
else 0;

def atEndTime = if secondsTillTime(endTime) == 0
then 1
else 0;``````
By only scanning during pre-market. You can also use the “within X bars” as a lookback period.

Search code here that uses SecondsFromTime and SecondsTillTime. You may need to adjust for your timezone.

I use a variable in all my scripts like

Code:
``input timeOffsetFromEST = -300; #hint timeOffsetFromEST: 24-hour time offset from EST (-300 for PST)``

and then

Code:
``````startTime = 0630 - timeOffsetFromEST;

and then maybe something like

Code:
``````def isActive = if SecondsTillTime(endTime) > 0 and SecondsFromTime(startTime) >= 0
then 1
else 0;

def atEndTime = if secondsTillTime(endTime) == 0
then 1
else 0;``````

@korygill

Let me explain a bit better

The following code finds the % change in the value of a stock from open of the same day with aggregation period set to DAY in my scanner. I have some other filters in the scan like average_vol and sizzle index.

Code:
``````def x = round(100*((close/open)-1),2);
plot y = if x >= 4 then 1 else if x <= -4 then 1 else 0;``````

What I was trying to do is, based on time after market opens, the % which is >=4 or <= -4 should change.

From
9:30 to 10:30 it should be 2.5%
10:30 to 13:30 it should be 3.5%
13:30 to 16:00 it should be 4.5%

My guess is that with daily aggregation, you never get time in 30 min increments to evaluate. Hence the constant return.

87k+ Posts
252 Online

## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?