Using 'date' to list a range of dates


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Using 'date' to list a range of dates
# 1  
Old 10-14-2010
MySQL Using 'date' to list a range of dates

Hi guys,

I have been trying to create a list of dates from a certain range, ie.
range from 01011950 to 31122000

But when my below code reaches certain dates, it comes up with a;
'date: invalid date 'yyyy-mm-dd -d 1day'


Sofar I have come up with the following, slow and ugly;

Code:
#!/bin/bash
# Create a wordlist based on dates in the format
# ddmmyyyy
# date doesnt seem to like certain dates resulting in a 
# 'date: invalid date 'yyyy-mm-dd -d 1day' 
#
# Although the input needs to be yyyy-mm-dd
# the output with the below script will be ddmmyyyy
# Its slow and suppose it would be quicker if it wasnt 
# 'teed' to screen, but what else are you gonna stare at..
#
echo "Enter the starting date"
echo "must be in the format yyyy-mm-dd"
(tput bold && tput setaf 1)
read START_DATE
(tput sgr 0) 
echo "Enter the ending date"
echo "must be in the format yyyy-mm-dd"
(tput bold && tput setaf 1)
read END_DATE
(tput sgr 0)
# List all dates in between the above dates

echo $START_DATE | tee r_dates.txt
while true
do
START_DATE=$( date +%Y-%m-%d -d "$START_DATE -d 1day" )
echo $START_DATE | tee -a r_dates.txt
if [ "$START_DATE" == "$END_DATE" ]
then 
awk -F- '{print $3 $2 $1}' r_dates.txt > datelist.txt
rm r_dates.txt
(tput bold && tput setaf 1)
echo "wordlist 'datelist.txt' created"
(tput sgr 0)
exit
fi
done

Can anyone explain to me why 'date' is giving an error when it reaches certain dates ?

For instance, when trying 2000-01-01 to 2050-12-31 using
the above code, an error is reported when it reaches
2038-01-19 ;
date: invalid date `2038-01-19 -d 1day'

Would appreciate it if someone can point me in the right direction with this !

Thanks - TAPE
# 2  
Old 10-14-2010
That date is creeping up on us fast.
Year 2038 problem - Wikipedia, the free encyclopedia
# 3  
Old 10-14-2010
Ahh.. my bad, I didnt even think to google that kind of error :|
Thought it would likely be the terrible coding Smilie

Thanks for the reply !

Does this kind of error occur on other dates ? I shall be doing some testing, but at least if I run into some weird errors I shall have a better understanding why..
# 4  
Old 10-14-2010
Yes, any date before 1901-12-13
# 5  
Old 10-14-2010
Thanks for the response !

It certainly makes the results go haywire....
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Display data from a range of dates

I have a data in a file called SCHED which has 5 columns: sched no, date, time, place and remarks. The image is shown below. http://dl.dropbox.com/u/54949888/Screenshot%20from%202013-01-02%2002%3A42%3A25.png Now, I want to display only the schedules which fall under a certain date range which... (2 Replies)
Discussion started by: angilulu
2 Replies

2. UNIX for Advanced & Expert Users

Help with ksh script to list, then cp files from a user input date range

Hi, I'm quite new to ksh scripting, can someone help me with this. Requirements: I need to create a script that list the files from a user input date range. e. g. format of file: *c1*log.2012-12-22-14-00* *c1*log.2012-12-22-14-00* *c1*log.2012-12-22-14-00*... (1 Reply)
Discussion started by: chococrunch6
1 Replies

3. Emergency UNIX and Linux Support

show div on select - range of dates

Hi, I am sure this is simple, but I am breaking my head. I need 1 page with at the top a range of dates, 2002, 2003, 2004 etc If you select 2002 it will show the content of 1 div, if you select 2002 the content of another div. this is for showing announcements on a site, right now there... (1 Reply)
Discussion started by: lawstudent
1 Replies

4. Shell Programming and Scripting

ksh compare dates INSIDE a file (ie date A is > date B)

In KSH, I am pasting 2 almost identical files together and each one has a date and time on each line. I need to determine if the first instance of the date/time is greater than the 2nd instance of the date/time. If the first instance is greater, I just need to echo that line. I thought I would... (4 Replies)
Discussion started by: right_coaster
4 Replies

5. Shell Programming and Scripting

Need to capture dates between start date and end date Using perl.

Hi All, Want to get all dates and Julian week number for that date between the start date and end date. How can I achive this using perl? (To achive above functionality, I was connecting to the database from DB server. Need to execute the same script in application server, since databse... (6 Replies)
Discussion started by: Nagaraja Akkiva
6 Replies

6. Shell Programming and Scripting

List files with Date Range and Zip it

Hi all, I am using the below script which display the files in the folder with the date range we specify. I want to add extra functionality that, The listing files should be zipped using gzip. I tried to add exec gzip at the last line but it is not working. Suggestions please. ... (2 Replies)
Discussion started by: nokiak810
2 Replies

7. Shell Programming and Scripting

Generate quarter dates with begin date and end date

Hi All, I am trying to generate quarter dates with user giving input as begin date and end date. Example: Input by user: begin_date = "2009-01-01" end_date = 2010-04-30" required output: 2009-01-01 2009-03-31 09Q01 2009-04-01 2009-06-30 09Q02 . . till 2010-01-01 2010-03-31 10Q01 ... (9 Replies)
Discussion started by: sol_nov
9 Replies

8. Shell Programming and Scripting

pull range of dates/times and put into new file

Need to pull from a range of dates/times (ex. 6:00 AM March 3 through 6:00 AM March 4) from a folder and put those file names in a new file to process later. Dates would not be hard dates but dates from the folder directory, how would I do that? (9 Replies)
Discussion started by: freddie999
9 Replies

9. UNIX for Dummies Questions & Answers

How to list file names in a certain date range using ls command?

Hi experts, I Need to print file names in a certain date range using ls:confused:. Please help me with any sample script. Thanks a lot in advance. Regards, Satish (4 Replies)
Discussion started by: satish.vutti
4 Replies

10. UNIX for Dummies Questions & Answers

Display dates within a given date range

Hi All, I have a requirement to display all the dates within the provided (through user input) date range. For eg: If I enter 28012009 (as From date in the format 'DDMMYYYY') and 02022009(as To date in the format 'DDMMYYYY'), the output should be all dates occuring between the from and to... (11 Replies)
Discussion started by: sunpraveen
11 Replies
Login or Register to Ask a Question