Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8264801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T04:35:08+00:00 2026-06-08T04:35:08+00:00

I would like to write a bash script that prints out the date in

  • 0

I would like to write a bash script that prints out the date in the following format:

20120205_16
(year)(month)(day)_(24 hour)

so the command to do this for the current date is:

date +'20%y%m%d_%H'

What i would like to do is print every date like this (using a for loop or something) from a specified date to another. For example:

20120205_16 -> 20120305_18 would be:

20120205_16
20120205_17
20120205_18
...
20120305_17
20120305_18

Obviously the two hard bits here are specifying the date and incrementing by hour.

Is it possible to do this easily with date or another method?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T04:35:10+00:00Added an answer on June 8, 2026 at 4:35 am

    First, you get time_t values using the %s format:

    start=$(date --date '5 feb 2012 16:00' +%s)
    stop=$(date --date '5 mar 2012 18:00' +%s)
    

    These are expressed in seconds. You can use a for loop on their values, increasing them by 1 hour (3600 seconds):

    for t in $(seq ${start} 3600 ${stop})
    do
        date --date @${t} +'%Y%m%d_%H'
    done
    

    Note the @ which is used to express times obtained through %+s in the --date argument.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to write a bash script or a few shell commands that
I would like to write a bash script in Linux that executes a program
I would like to write a query that returns a single date value, that
I'm trying to write (what I thought would be) a simple bash script that
I'm trying to write a bash script that would modify all occurrences of a
The day came when I had to write a BASH script that walks arbitrary
I am new to bash scripting and would like to write a bash script
I'd like to write a Bash script that reports a sum. I'm starting with
I would like to write a script that installs JAGS and rjags on a
I would like to write a function that creates a plot of a set

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.