Sponsored Content
Full Discussion: Date calculation
Top Forums Shell Programming and Scripting Date calculation Post 302750277 by kshji on Monday 31st of December 2012 10:51:29 AM
Old 12-31-2012
I have write some answers about date calc, ex. function or ksh printf command.

Ex. using ksh93

Code:
#!/usr/bin/ksh93
str="11:30:02-31.11.12"
# convert - and . to spaces 
str=${str/-/ }
str=${str//\./ }

# generic version
read time day month year << EOF
$str
EOF
# ksh93 can use also pipe reading
echo $str | read time day month year

year="20$year"
datestr="$year-$month-$day+$time" 
epoc1=$(printf "%(%#)T" "$datestr")
epoc2=$(printf "%(%#)T" now )

((d=60*60*24))
((h=60*60))

(( diff=epoc2-epoc1 ))
(( daycnt=diff/d ))
(( hcnt=(diff-daycnt*d)/h  ))
(( mcnt= (diff - daycnt*d - hcnt*h ) / 60 ))

printf "%dD %dH %dM\n" $daycnt $hcnt $mcnt

Or using gnu date command. Search from this site "date gnu calc"
 

10 More Discussions You Might Find Interesting

1. Programming

date calculation program

Hi One of my vendor based tool is giving date in no. of days since 1900-01-01. So, I want to display in CCYYMMDD format. For ex:- Vendor based tool is giving as 38790 days since 1900-01-01 corresponding to12/sep/2006 Does anybody has the... (1 Reply)
Discussion started by: axes
1 Replies

2. Shell Programming and Scripting

Date Calculation

Hi experts, Can you please help me in calculating the future date using unix shell scripting.. for example lets say todays date is 29-sep-2008 i wanna calculate the date after 365 days... hence the date must be 29-sep-2009.. Quick response is appreciable. thanks in... (2 Replies)
Discussion started by: subhendu81
2 Replies

3. UNIX for Advanced & Expert Users

date calculation scripts(hp-ux)

Hi all, i need a script that can check if users did an operation within 3 days,if not delete all the logs of users who did not perform any activity after 3 days.therefore script should be able to use current date and verify last date user performed activity and see if it is greater or less than 3... (3 Replies)
Discussion started by: tomjones
3 Replies

4. Shell Programming and Scripting

Problems with date calculation

Hello all. I'm writing a script that should work with some files being sure that them were created a concrete day (0, 1, 2 or 3 days before script execution). This task should be done under Solaris and Linux hosts with different versions (Solaris 8, 9 and 10, Suse 9 and 10) so I'm trying to make... (3 Replies)
Discussion started by: nefeli
3 Replies

5. Shell Programming and Scripting

Date time calculation

hello guys, I had been to many forums and many topics in this site as well for my question but did not get any solution. My question is how i can get y'day date with time stamp today is 20100729103819 and i am looking for output as 20100728103819. in simple words as we do in oracle sysdate-1... (4 Replies)
Discussion started by: lokaish23
4 Replies

6. Shell Programming and Scripting

Date calculation script

hello! I need a date calculation script that need to do that: ./date.sh 20090312 and the script need to give me which day is it for example monday friday or what else! can anyone help me?? its really urgent :S thx the help! (7 Replies)
Discussion started by: impish
7 Replies

7. Shell Programming and Scripting

Date calculation

I have to run a shell , only if file_a.txt is updated correctly before 1hr. that is, file_a.txt 2011_09_21__14:10:20 --> any format.. And the shell can be like, if ; then Run some shell update file_a.txt with (date now) fi how to do this ? (6 Replies)
Discussion started by: linuxadmin
6 Replies

8. Shell Programming and Scripting

Date calculation, a little different...

Hello eveyone, I am tasked to write an (n)awk script to calculate the days between dates. Now before anyone chastizes me on how many forums there are on date calculation, I have no seen one that takes into account the Julian calender as well. As most know, September of 1752 is when we (the US)... (2 Replies)
Discussion started by: csharp100
2 Replies

9. UNIX for Dummies Questions & Answers

Need help regarding date calculation

Hi All, I need to calculate the date for monday to friday. Say today is 10.oct.2014 then I need to calculate the date as 09.oct.2014. If today is 13.oct.2014 then I need to calculate the date as 10.oct.2014. If its 03.Nov.2014 then date calculated must be 31.oct.2014. Please help in in... (2 Replies)
Discussion started by: abhi_123
2 Replies

10. UNIX for Dummies Questions & Answers

Date calculation in UNIX

I want to automate change in 'from yyyy/mm/dd to yyyy/mm/dd' every month in a unix program. For example in this month 'from yyyy/mm/dd to yyyy/mm/dd' is 'from 2014/10/01 to 2014/11/01' next month it should be 'from 2014/11/01 to 2014/12/01' Can any one provide me the code for the above... (2 Replies)
Discussion started by: srinivas kasett
2 Replies
TCUCODEC(1)							   Tokyo Cabinet						       TCUCODEC(1)

NAME
tcucodec - popular encoders and decoders DESCRIPTION
The command `tcucodec' is a tool to use encoding and decoding features. This command is used in the following format. `file' specifies a input file. If it is omitted, the standard input is read. tcucodec url [-d] [-br] [-rs base] [file] Perform URL encoding and its decoding. tcucodec base [-d] [file] Perform Base64 encoding and its decoding. tcucodec quote [-d] [file] Perform quoted-printable encoding and its decoding. tcucodec mime [-d] [-en name] [-q] [-on] [-hd] [-bd] [-part num] [file] Perform MIME encoding and its decoding. tcucodec hex [-d] [file] Perform hexadecimal encoding and its decoding. tcucodec pack [-d] [-bwt] [file] Perform Packbits encoding and its decoding. tcucodec tcbs [-d] [file] Perform TCBS encoding and its decoding. tcucodec zlib [-d] [-gz] [file] Perform ZLIB encoding and its decoding. tcucodec bzip [-d] [file] Perform BZIP2 encoding and its decoding. tcucodec xml [-d] [-br] [file] Process XML. By default, escape meta characters. tcucodec cstr [-d] [-js] [file] Perform C-string escaping and its unescaping. tcucodec ucs [-d] [-un] [-kw str] [file] Convert UTF-8 string into UCS-2 array. tcucodec hash [-crc] [-ch num] [file] Calculate the hash value. By default, use MD5 function. tcucodec cipher [-key str] [file] Perform stream cipher and its decipher. tcucodec date [-ds str] [-jl num] [-wf] [-rf] Process date string. By default, print the current UNIX time. tcucodec tmpl [-var name value] [file] Perform template serialization. tcucodec conf [-v|-i|-l|-p] Print some configurations. Options feature the following. -d : perform decoding (unescaping), not encoding (escaping). -br : break up URL or XML into elements. -rs base : specify the base URL and resolve the relative URL. -en name : specify the input encoding, which is UTF-8 by default. -q : use quoted-printable encoding, which is Base64 by default. -on : output the charset name when decoding. -bd : perform MIME parsing and output the body. -hd : perform MIME parsing and output the headers. -part num : perform MIME parsing and output the specified part. -bwt : convert by BWT as preprocessing. -gz : use GZIP format. -crc : use CRC32 function. -js : use JSON compatible format. -un : perform UCS normalization. -kw str : generate KWIC string. -ch num : use consistent hashing function. -key str : specify the cipher key. -ds str : specify the time. -jl num : specify the jet lag. -wf : format the output in W3CDTF. -rf : format the output in RFC 1123 format. -var name value : specify a template variable. -v : show the version number of Tokyo Cabinet. -i : show options to include the headers of Tokyo Cabinet. -l : show options to link the library of Tokyo Cabinet. -p : show the directory path of the commands of Tokyo Cabinet. This command returns 0 on success, another on failure. SEE ALSO
tcutest(1), tcumttest(1), tcutil(3), tokyocabinet(3) Man Page 2011-02-12 TCUCODEC(1)
All times are GMT -4. The time now is 09:04 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy