LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-21-2013, 05:01 PM   #1
ip_address
Member
 
Registered: Apr 2012
Distribution: RedHat
Posts: 42

Rep: Reputation: 2
generate dates between two dates


Hi,

Is there a way to generate dates between two dates taking care of leap years? For example, generate all the dates between 2012-10-11 and 2014-05-01. Thanks!

Code:
2012-10-11
2012-10-12
2012-10-13
.
.
.
2012-10-30
2012-10-31
2012-11-01
.
.
.
2014-04-30
2014-05-01
 
Old 03-21-2013, 05:07 PM   #2
OAnimal74
LQ Newbie
 
Registered: Mar 2013
Posts: 8

Rep: Reputation: Disabled
Of course there is. In which programming language?
 
Old 03-21-2013, 05:12 PM   #3
ip_address
Member
 
Registered: Apr 2012
Distribution: RedHat
Posts: 42

Original Poster
Rep: Reputation: 2
can we do it in bash / awk? Thanks!
 
Old 03-21-2013, 05:19 PM   #4
OAnimal74
LQ Newbie
 
Registered: Mar 2013
Posts: 8

Rep: Reputation: Disabled
Not that familiar with those two languages unfortunately.
 
Old 03-21-2013, 05:28 PM   #5
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,318

Rep: Reputation: 351Reputation: 351Reputation: 351Reputation: 351
Code:
#!/bin/sh
d1=2012-10-11
d2=2014-05-01
while [ $d1 != $d2 ] ; do
        echo $d1
        d1=$(date -d "$d1 + 1 day" +%F)
done
echo $d2

Edit:
Should probably need some validation that the dates are proper, and that d2 is not before d1. And first I forgot to "echo $d2".

Last edited by Guttorm; 03-21-2013 at 05:45 PM.
 
1 members found this post helpful.
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
About Dump Dates anilbh Linux - Newbie 7 03-08-2006 02:33 AM
Loop that will generate dates from now to beginning of year mrobertson Programming 1 10-06-2005 10:02 AM
Subtracting dates chrisk5527 Linux - General 6 06-10-2004 03:57 PM
File dates. vexer Programming 5 04-28-2004 01:14 AM
need to manipulate dates clsonnt Programming 5 08-19-2003 11:07 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:06 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration