# Extract TIME

**URL:** <https://community.unix.com/t/extract-time/171070>\
**Category:** UNIX for Dummies Questions & Answers\
**Created:** [May 8, 2007, 9:50am UTC](https://community.unix.com/t/extract-time/171070 "2007-05-08T09:50:21Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ndoggy020](https://community.unix.com/letter_avatar/ndoggy020/32/5_5575768a8748004e209b776fc1b2916d.png) [@ndoggy020](https://community.unix.com/u/ndoggy020)\
**Post date:** [May 8, 2007, 9:50am UTC](https://community.unix.com/t/extract-time/171070/1 "2007-05-08T09:50:21Z")

</div>

Hey guys.

How would I go about extracting the time from the system clock and inserting it into a variable?

Any thoughts?

---

<div class="post-metadata">

**Author:** ![blowtorch](https://community.unix.com/user_avatar/community.unix.com/blowtorch/32/136_2.png) [@blowtorch](https://community.unix.com/u/blowtorch)\
**Post date:** [May 8, 2007, 10:15am UTC](https://community.unix.com/t/extract-time/171070/2 "2007-05-08T10:15:03Z")

</div>

Look at the date command. The different formats will allow you to save that value in a variety of ways.

---

<div class="post-metadata">

**Author:** ![ndoggy020](https://community.unix.com/letter_avatar/ndoggy020/32/5_5575768a8748004e209b776fc1b2916d.png) [@ndoggy020](https://community.unix.com/u/ndoggy020)\
**Post date:** [May 8, 2007, 10:18am UTC](https://community.unix.com/t/extract-time/171070/3 "2007-05-08T10:18:57Z")

</div>

I think I got it,

ts=`date +%H%M`

Thanks again.

---

<div class="post-metadata">

**Author:** ![ndoggy020](https://community.unix.com/letter_avatar/ndoggy020/32/5_5575768a8748004e209b776fc1b2916d.png) [@ndoggy020](https://community.unix.com/u/ndoggy020)\
**Post date:** [May 8, 2007, 10:20am UTC](https://community.unix.com/t/extract-time/171070/4 "2007-05-08T10:20:00Z")

</div>

I was givin the task to, Glean the time only and write a small script that echo's before or after the time you specify.

Would this work:

ts=`date +%H%M`

echo ts

if ts \> 0900  
echo after  
else  
echo before  
fi

---

<div class="post-metadata">

**Author:** ![blowtorch](https://community.unix.com/user_avatar/community.unix.com/blowtorch/32/136_2.png) [@blowtorch](https://community.unix.com/u/blowtorch)\
**Post date:** [May 8, 2007, 8:06pm UTC](https://community.unix.com/t/extract-time/171070/5 "2007-05-08T20:06:44Z")

</div>

Is this homework? If it is, its against the rules.
