Sponsored Content
Top Forums Shell Programming and Scripting convert mmddyy date format to ccyyddd format?? Post 302090786 by anbu23 on Wednesday 27th of September 2006 01:06:48 PM
Old 09-27-2006
try this

Code:
scp
mm=`expr substr "$1" 1 2`
dd=`expr substr "$1" 3 2`
yyyy="20""`expr substr "$1" 5 2`"

ddd=`cal_days $yyyy $mm $dd`

echo "$yyyy$ddd"

Perl script
Code:
cal_days
#!/bin/perl
use Time::Local;
my $year=shift;
my $month=shift;
my $day=shift;
my $time = timelocal(0,0,23,$day,$month-1,$year-1900);
my $time1 = timelocal(0,0,0,1,0,$year-1900);
my $days = ( $time -$time1 ) / 86400;
printf("%.0f", $days);


Code:
$scp 092706
2006270

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Convert date format

Hi All, Need your help in converting a date format in ksh. I'm currently working on SUN os where my script is getting a date from a table. The result returns to ksh in this format: 17-JUL-08 How do i convert this string to a date format like yyyymmdd? I tried #!/bin/ksh d="17-JUL-08"... (5 Replies)
Discussion started by: agathaeleanor
5 Replies

2. Shell Programming and Scripting

Convert Epoch time format to normal date time format in the same file

I have a file named "suspected" with series of line like these : {'protocol': 17, 'service': 'BitTorrent KRPC', 'server': '219.78.120.166', 'client_port': 52044, 'client': '10.64.68.44', 'server_port': 8291, 'time': 1226506312L, 'serverhostname': ''} {'protocol': 17, 'service': 'BitTorrent... (3 Replies)
Discussion started by: rk4k
3 Replies

3. Shell Programming and Scripting

convert date format to mysql date format in log file

I have a comma delimited log file which has the date as MM/DD/YY in the 2nd column, and HH:MM:SS in the 3rd column. I need to change the date format to YYYY-MM-DD and merge it with the the time HH:MM:SS. How will I got about this? Sample input 02/27/09,23:52:31 02/27/09,23:52:52... (3 Replies)
Discussion started by: hazno
3 Replies

4. Shell Programming and Scripting

Convert date to Unix format

Dear Expert How to convert date in format of YYYY-MM-DD HH:MM:SS to unix format using a script or command if avaliable Example "2011-05-15 18:00:00" is converted to 1330970400 I tried to use option d in date command but no use, Im using solaris 10 Thanks a lot (12 Replies)
Discussion started by: yahyaaa
12 Replies

5. Shell Programming and Scripting

convert date format

I've been using this thread: https://www.unix.com/shell-programming-scripting/58675-change-date-dd-mmm-yyyy-mm-dd-yyyy.html and https://www.unix.com/shell-programming-scripting/14655-changing-yyyy-mm-dd-ddmmyy.html and this code: on this format: 05/16/2008 18:30:49 Installation 48985and I'm... (3 Replies)
Discussion started by: dba_frog
3 Replies

6. Shell Programming and Scripting

Convert any date format into yyyy/mm/dd

How can I convert any user inputted date into yyyy/mm/dd ? For example user can input date one of the following 20120121 , 2012-01-21 ,01/21/2012,01/21/2012 etc But I need to convert any of the date entered by user into yyyy/mm/dd (2012/01/2012). Any suggestion. Thanks in advance this is... (1 Reply)
Discussion started by: ZeroHedge
1 Replies

7. Shell Programming and Scripting

How to increment date using "for loop" in format MMDDYY inside the shell script?

Need to increment the date from "currentdate + 90days" inside the for loop (i=1 to i=50) (5 Replies)
Discussion started by: aroragaurav.84
5 Replies

8. Shell Programming and Scripting

Convert string into date format

Hi, I am getting the below string as a input for date. 12/03/2013 11:02 AM I want to change this date as 03-DEC-2013 11:02 AM. Could you please help on this. Thanks Chelladurai (4 Replies)
Discussion started by: ckchelladurai
4 Replies

9. Shell Programming and Scripting

Convert Date Format

Hello, I want to change the format of date value in variable. e.g. cur_date = '2013/03/13 14:24:50' (yyyy/mm/dd hh24:mi:ss) I want to change this to '13-MAR-2013 14:24:50 Following code coverts the current date to format I am looking for. But I do not know how this can be done for a date... (8 Replies)
Discussion started by: cartrider
8 Replies

10. Shell Programming and Scripting

Convert date format

Hi guys I am looking to convert this kind of entry in a txt file 26/04/2008 to April 2008 Note : this is not using the date command , these are date entries in a file can i do this with sed ? Use code tags, thanks. (5 Replies)
Discussion started by: johnnybananas
5 Replies
Image::ExifTool::Shift(3)				User Contributed Perl Documentation				 Image::ExifTool::Shift(3)

NAME
Image::ExifTool::Shift.pl - ExifTool time shifting routines DESCRIPTION
This module contains routines used by ExifTool to shift date and time values. DETAILS
Time shifts are applied to standard EXIF-formatted date/time values (ie. "2005:03:14 18:55:00"). Date-only and time-only values may also be shifted, and an optional timezone (ie. "-05:00") is also supported. Here are some general rules and examples to explain how shift strings are interpreted: Date-only values are shifted using the following formats: 'Y:M:D' - shift date by 'Y' years, 'M' months and 'D' days 'M:D' - shift months and days only 'D' - shift specified number of days Time-only values are shifted using the following formats: 'h:m:s' - shift time by 'h' hours, 'm' minutes and 's' seconds 'h:m' - shift hours and minutes only 'h' - shift specified number of hours Timezone shifts are specified in the following formats: '+h:m' - shift timezone by 'h' hours and 'm' minutes '-h:m' - negative shift of timezone hours and minutes '+h' - shift timezone hours only '-h' - negative shift of timezone hours only A valid shift value consists of one or two arguments, separated by a space. If only one is provided, it is assumed to be a time shift when applied to a time-only or a date/time value, or a date shift when applied to a date-only value. For example: '7' - shift by 1 hour if applied to a time or date/time value, or by one day if applied to a date value '2:0' - shift 2 hours (time, date/time), or 2 months (date) '5:0:0' - shift 5 hours (time, date/time), or 5 years (date) '0:0:1' - shift 1 s (time, date/time), or 1 day (date) If two arguments are given, the date shift is first, followed by the time shift: '3:0:0 0' - shift date by 3 years '0 15:30' - shift time by 15 hours and 30 minutes '1:0:0 0:0:0+5:0' - shift date by 1 year and timezone by 5 hours A date shift is simply ignored if applied to a time value or visa versa. Numbers specified in shift fields may contain a decimal point: '1.5' - 1 hour 30 minutes (time, date/time), or 1 day (date) '2.5 0' - 2 days 12 hours (date/time), 12 hours (time) or 2 days (date) And to save typing, a zero is assumed for any missing numbers: '1::' - shift by 1 hour (time, date/time) or 1 year (date) '26:: 0' - shift date by 26 years '+:30 - shift timezone by 30 minutes Below are some specific examples applied to real date and/or time values ('Dir' is the applied shift direction: '+' is positive, '-' is negative): Original Value Shift Dir Shifted Value --------------------- ------- --- --------------------- '20:30:00' '5' + '01:30:00' '2005:01:27' '5' + '2005:02:01' '11:54:00' '2.5 0' - '23:54:00' '2005:11:02' '2.5 0' - '2005:10:31' '2005:11:02 11:54:00' '2.5 0' - '2005:10:30 23:54:00' '2004:02:28 08:00:00' '1 1.3' + '2004:02:29 09:18:00' '07:00:00' '-5' + '07:00:00' '07:00:00+01:00' '-5' + '07:00:00-04:00' '07:00:00Z' '+2:30' - '07:00:00-02:30' '1970:01:01' '35::' + '2005:01:01' '2005:01:01' '400' + '2006:02:05' '10:00:00.00' '::1.33' + '09:59:58.67' NOTES
The format of the original date/time value is not changed when the time shift is applied. This means that the length of the date/time string will not change, and only the numbers in the string will be modified. The only exception to this rule is that a 'Z' timezone is changed to '+00:00' notation if a timezone shift is applied. A timezone will not be added to the date/time string. TRICKY
This module is perhaps more complicated than it needs to be because it is designed to be very flexible in the way time shifts are specified and applied... The ability to shift dates by Y years, M months, etc, is somewhat contradictory to the goal of maintaining a constant shift for all time values when applying a batch shift. This is because shifting by 1 month can be equivalent to anything from 28 to 31 days, and 1 year can be 365 or 366 days, depending on the starting date. The inconsistency is handled by shifting the first tag found with the actual specified shift, then calculating the equivalent time difference in seconds for this shift and applying this difference to subsequent tags in a batch conversion. So if it works as designed, the behaviour should be both intuitive and mathematically correct, and the user shouldn't have to worry about details such as this (in keeping with Perl's "do the right thing" philosophy). AUTHOR
Copyright 2003-2010, Phil Harvey (phil at owl.phy.queensu.ca) This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. SEE ALSO
Image::ExifTool(3pm) perl v5.12.1 2010-01-04 Image::ExifTool::Shift(3)
All times are GMT -4. The time now is 03:03 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy