Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Hour in t TIME using batch script

Posted on 2009-04-23
6
Medium Priority
?
487 Views
Last Modified: 2013-11-27
I would lik to get the Hour value alone from a Time stamp ,

TIME = 12:40:48.35 , I would need only the '12' , hw can i do this in a batch script.
0
Comment
Question by:FranklinRaj22
6 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 24217877

Left([Time],Instr([time],":")-1)  ' will give you 12 from the sample posted
0
 
LVL 38

Expert Comment

by:Shift-3
ID: 24218021
In a batch script you would extract those characters with %time:~0,2%.

See here for more information on variable substrings.
0
 
LVL 16

Expert Comment

by:t0t0
ID: 24222555
Get hour digits from system time:

   set hour=%time%
   set hour=%hour:~0,2%
   set hour=%hour: =0%

(see next comment for expanation)
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 16

Expert Comment

by:t0t0
ID: 24222556
EXPLANATION:

     hour = %time%              =   8:21:38.91       - get the full system time string
     hour = %hour:~0,2%     =   8                      - extract first 2 digits
     hour = %hour: =0%       = 08                      - convert spaces to zeros

     hour = %time%              = 12:21:38.91       - get the full system time string
     hour = %hour:~0,2%     = 12                      - extract first 2 digits
     hour = %hour: =0%       = 12                      - convert does not alter result as there are no spaces
0
 
LVL 16

Accepted Solution

by:
t0t0 earned 2000 total points
ID: 24222641
EXPLANATION 2:

When the hour is between 1 and 9, the system uses a space followed by a single digit as shown in my previous comment.

If you only want a single digit ('8') instead of two digits ('08') when the hour is between 1 and 9, then you can use the following subtle variant:

     hour = %time%              =   8:21:38.91       - get the full system time string
     hour = %hour:~0,2%     =   8                      - extract first 2 digits
     hour = %hour: =%         = 8                        - strip away leading space

     hour = %time%              = 12:21:38.91       - get the full system time string
     hour = %hour:~0,2%     = 12                      - extract first 2 digits
     hour = %hour: =0%       = 12                      - uneffected
0
 

Author Comment

by:FranklinRaj22
ID: 25390190
ok
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question