Sponsored Content
Top Forums Shell Programming and Scripting Need help with date arithmetic please Post 303000301 by ektubbe on Sunday 9th of July 2017 12:39:08 AM
Old 07-09-2017
Quote:
Originally Posted by MadeInGermany
The "value too great for base" happens because there is a number with a leading zero, and bash assumes octal, and 8 is too high for an octal number.
It happens with
Code:
day=$((day+1))

or later with month.
As always there is an escape from such (mis)feature: a 10# prefix forces a base10=decimal
Code:
day=$((10#$day+1))
month=$((10#$month))

Now the leading zero are removed.

---------- Post updated at 11:15 ---------- Previous update was at 10:52 ----------

You certainly want
Code:
if [ \( $year4 -eq 0 -a \
        $year100 -ne 0 \) -o \
     $year400 -eq 0 ]
then
declare -a  max_month=(0 31 29 31 30 31 30 31 31)
fi

As Jim said, such calculations are error prone.
perl is safer because it uses the libc routines.
Thanks madeingermany...I tried but the error is still because of line I mentioned in my first post n I am using AIX so most of the commands don't work...I need to do date calculation for an arbitrary date so tz doesn't work for me either Smilie
~Ekta
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

time arithmetic

Can anyone help please. I am writing a kourne shell script and I am unsure how to do the following: I have extracted a time string from a logfile, and I have another time string I want to compare it to to see if it's later than the time I'm comparing with. i.e. expectedSLA="23:00:00", ... (2 Replies)
Discussion started by: csong2
2 Replies

2. UNIX for Dummies Questions & Answers

arithmetic problem

i am used to making scripts for hp-ux. but lately i tried to make some for solaris. the problem is that when i tried to execute it it gave me an error the "let: not found". why is that? how can i perform an arithmetic function in the solaris shell script? thanks :) (2 Replies)
Discussion started by: inquirer
2 Replies

3. Shell Programming and Scripting

arithmetic in ksh

Helloo.. I am trying one very simple thing I could not find anything on google.. I have 2 integer variable..and I need to do division...in ksh where $catch and $num are integer variable.. I tryed with this: printf "%0.2f" $final=$catch/$num but it does not work.. any help is... (12 Replies)
Discussion started by: amon
12 Replies

4. Shell Programming and Scripting

How to perform arithmetic operation on date

Hi all, I would appreciate if anyone knows how to perform adding to date. As for normal date, i can easily plus with any number. But when it comes to month end say for example 28 Jun, i need to perform a plus with number 3, it will not return 1 Jul. Thanks in advance for your help. (4 Replies)
Discussion started by: agathaeleanor
4 Replies

5. Shell Programming and Scripting

Arithmetic on timestamps

Hi Friends, please advise on shell script to add two time stamps for example : a=12:32 b=12:00 c=a+b=00:32 please help me to find shell script to add to two time stamps, as i need to convert time from EST to GMT or SST to prepare status of jobs in unix and to specify estimated time to... (3 Replies)
Discussion started by: balireddy_77
3 Replies

6. UNIX for Dummies Questions & Answers

Arithmetic: how to??

Hello all, I'd like to know how to perform arithmetic on multiple files. I have got many tab-delimited files. Each file contains about 2000 rows and 2000 columns. What I want to do is to to sum the values in each row & column in every file. The following explains what I want to do; ... (9 Replies)
Discussion started by: Muhammad Rahiz
9 Replies

7. Shell Programming and Scripting

Date and time Arithmetic

Hi, I need to process a file which contains below data. Usually the files contains both Start and Finish time. but for Few records, it contains only Start. For those records I need to add the finish line by adding 5 minutes to Start time. Started BBIDX Tue Jun 1 15:15:11 EDT 2010 292308... (1 Reply)
Discussion started by: siba.s.nayak
1 Replies

8. Post Here to Contact Site Administrators and Moderators

Broken link FAQ date arithmetic with shell

page unix com/answers-frequently-asked-questions/13785-yesterdays-date-date-arithmetic.html Date Arithmetic with the Shell has link of www samag com/documents/s=8284/sam0307b/0307b.htm which is no longer. Is this the correct place to post this?:confused: and I got message... (1 Reply)
Discussion started by: dgerman
1 Replies

9. Shell Programming and Scripting

Help needed with some date arithmetic

I have a file (main.lst) containing a list of dates in DDMMYYYY format. The dates will mostly be the same but it is possible to have multiple dates and these need not be in chronological order. I have another file containing another list of dates (holidays.lst). The task is to get the latest... (5 Replies)
Discussion started by: elixir_sinari
5 Replies

10. Shell Programming and Scripting

Arithmetic with bash

I need to divide the number of white spaces by total number of characters in a file using bash. I am able to get the number of white spaces correctly using: tr -cd < afile | wc -c I am also able to get the total number of characters using: wc -c afile How do I divide the first... (2 Replies)
Discussion started by: ngabrani
2 Replies
HTML::FormHandler::Field::Date(3pm)			User Contributed Perl Documentation		       HTML::FormHandler::Field::Date(3pm)

NAME
HTML::FormHandler::Field::Date - a date field with formats VERSION
version 0.40013 SUMMARY
This field may be used with the jQuery Datepicker plugin. You can specify the format for the date using jQuery formatDate strings or DateTime strftime formats. (Default format is format => '%Y-%m-%d'.) d - "%e" - day of month (no leading zero) dd - "%d" - day of month (two digit) o - "%{day_of_year}" - day of the year (no leading zeros) oo - "%j" - day of the year (three digit) D - "%a" - day name short DD - "%A" - day name long m - "%{day_of_month" - month of year (no leading zero) mm - "%m" - month of year (two digit) "%m" M - "%b" - month name short MM - "%B" - month name long y - "%y" - year (two digit) yy - "%Y" - year (four digit) @ - "%s" - Unix timestamp (ms since 01/01/1970) For example: has_field 'start_date' => ( type => 'Date', format => "dd/mm/y" ); or has_field 'start_date' => ( type => 'Date', format => "%d/%m/%y" ); You can also set 'date_end' and 'date_start' attributes for validation of the date range. Use iso_8601 formats for these dates ("yyyy-mm- dd"); has_field 'start_date' => ( type => 'Date', date_start => "2009-12-25" ); Customize error messages 'date_early' and 'date_late': has_field 'start_date' => ( type => 'Date, messages => { date_early => 'Pick a later date', date_late => 'Pick an earlier date', } ); If form has 'is_html5' flag active it will render <input type="date" ... /> instead of type="text" AUTHOR
FormHandler Contributors - see HTML::FormHandler COPYRIGHT AND LICENSE
This software is copyright (c) 2012 by Gerda Shank. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. perl v5.14.2 2012-06-25 HTML::FormHandler::Field::Date(3pm)
All times are GMT -4. The time now is 05:29 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy