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
Calendar::Simple(3pm)					User Contributed Perl Documentation				     Calendar::Simple(3pm)

NAME
Calendar::Simple - Perl extension to create simple calendars SYNOPSIS
use Calendar::Simple; my @curr = calendar; # get current month my @this_sept = calendar(9); # get 9th month of current year my @sept_2002 = calendar(9, 2002); # get 9th month of 2002 my @monday = calendar(9, 2002, 1); # get 9th month of 2002, # weeks start on Monday my @span = date_span(mon => 10, # returns span of dates year => 2006, begin => 15, end => 28); DESCRIPTION
A very simple module that exports one function called "calendar". calendar This function returns a data structure representing the dates in a month. The data structure returned is an array of array references. The first level array represents the weeks in the month. The second level array contains the actual days. By default, each week starts on a Sunday and the value in the array is the date of that day. Any days at the beginning of the first week or the end of the last week that are from the previous or next month have the value "undef". If the month or year parameters are omitted then the current month or year are assumed. A third, optional parameter, start_day, allows you to set the day each week starts with, with the same values as localtime sets for wday (namely, 0 for Sunday, 1 for Monday and so on). date_span This function returns a cur-down version of a month data structure which begins and ends on dates other than the first and last dates of the month. Any weeks that fall completely outside of the date range are removed from the structure and any days within the remaining weeks that fall outside of the date range are set to "undef". As there are a number of parameters to this function, they are passed using a named parameter interface. The parameters are as follows: year The required year. Defaults to the current year if omitted. mon The required month. Defaults to the current month if omitted. begin The first day of the required span. Defaults to the first if omitted. end The last day of the required span. Defaults to the last day of the month if omitted. start_day Indicates the day of the week that each week starts with. This takes the same values as the optional third parameter to "calendar". The default is 0 (for Sunday). This function isn't exported by default, so in order to use it in your program you need to use the module like this: use Calendar::Simple 'date_span'; EXAMPLE A simple "cal" replacement would therefore look like this: #!/usr/bin/perl -w use strict; use Calendar::Simple; my @months = qw(January February March April May June July August September October November December); my $mon = shift || (localtime)[4] + 1; my $yr = shift || (localtime)[5] + 1900; my @month = calendar($mon, $yr); print " $months[$mon -1] $yr "; print "Su Mo Tu We Th Fr Sa "; foreach (@month) { print map { $_ ? sprintf "%2d ", $_ : ' ' } @$_; print " "; } A version of this example, called "pcal", is installed when you install this module. Date Range This module will make use of DateTime.pm if it is installed. By using DateTime.pm it can use any date that DateTime can represent. If DateTime is not installed it uses Perl's built-in date handling and therefore can't deal with dates before 1970 and it will also have problems with dates after 2038 on a 32-bit machine. EXPORT "calendar" AUTHOR
Dave Cross <dave@mag-sol.com> ACKNOWLEDGEMENTS
With thanks to Paul Mison <cpan@husk.org> for the start day patch. COPYRIGHT
Copyright (C) 2002-2008, Magnum Solutions Ltd. All Rights Reserved. LICENSE
This script is free software; you can redistribute it and/or modify it under the same terms as Perl itself. SEE ALSO
perl, localtime, DateTime perl v5.10.1 2010-04-02 Calendar::Simple(3pm)
All times are GMT -4. The time now is 09:27 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy