Sponsored Content
Full Discussion: handling date field
Top Forums Shell Programming and Scripting handling date field Post 302113138 by cfajohnson on Tuesday 3rd of April 2007 06:00:19 PM
Old 04-03-2007
Quote:
Originally Posted by mgirinath
Is there any way we could change the date format listed below...

date I get is 03302007 (MMDDYYYY)
I need to change it to 20070330 (YYYYMMDD)

Separate the components, then put them back together in the order you want:

Code:
date=03302007
temp=${date#??}
month=${date%"$temp"}
day=${temp%????}
year=${temp#??}
newdate=$year$month$day

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Date Handling

In the shell which have the command prompt '$' ( Sorry i dunno wat shell is this), is there anyway to handle date input? Coz i need to accept a date from the user and wat i use is: read day;read month; read year; In this case user need to enter 3 time, is it any better way? Summore, is... (1 Reply)
Discussion started by: AkumaTay
1 Replies

2. Shell Programming and Scripting

Arrange date in a field

Hi all, If I have a flat file ID|Location|Date|Hostname|Age|Sex 1|SFO|06/02/24 12:12:34|hawkeye|35|M 2|LAX|06/02/24 13:12:35|sf49ers|30|M 3|OAK|06/02/25 11:12:36|goraiders|27|F 4|PIT|06/02/25 12:12:37|steeler|35|M How can I create an output 1|SFO|02/24/2006 12:12:34|hawkeye|35|M... (6 Replies)
Discussion started by: sabercats
6 Replies

3. Shell Programming and Scripting

How to Sort files on date field

:cool: Hi all, I have a pecular issue in sorting these files in Solaris environment. All the below files are modified on November 4th, but I want to sort these files as per date column (eg: 01May07_1623 = ddmmmyy_hhmm) Nov 4 18:27 SONYELEC00.GI22973.01May07_1623.gpg Nov 4 18:27... (4 Replies)
Discussion started by: shivaastrogun
4 Replies

4. Shell Programming and Scripting

Sort two columns in a field, one of them being a date

Hi, I have a set of columns in a csv file, my first row being an integer and 2nd being a date. I want to first sort it using the first column and then by the second. for e.g. i have , 1234,09/05/2009,hi 5678,01/01/2008,hi 1234,11/03/2006,hello 5678,28/07/2010,hello i tried this... (5 Replies)
Discussion started by: sweta_doshi
5 Replies

5. Shell Programming and Scripting

date field manipulation

I have a data file. Seperated by "|". The 19 th filed is a date field that occurs like this 11/02/2001 i need to convert into the below format 2001-11-02 for e.g.. i/p o/p should be can somebody throw some light (5 Replies)
Discussion started by: dsravan
5 Replies

6. UNIX for Advanced & Expert Users

change field 2 date format

from this input WEBELSOLAR,29122009,1:1 WIPRO,15062010,2:3 ZANDUREALT,18012007,1:3 i want output as WEBELSOLAR,20091229,1:1 WIPRO,20100615,2:3 ZANDUREALT,20070118,1:3 basically input is in ddmmyyyy format and i was to convert it to yyyymmdd format (1 Reply)
Discussion started by: manishma71
1 Replies

7. Shell Programming and Scripting

Check if a date field has date or timestamp or date&timestamp

Hi, In a field, I should receive the date with time stamp in a particular field. But sometimes the vendor sends just the date or the timestamp or correctl the date&timestamp. I have to figure out the the data is a date or time stamp or date&timestamp. If it is date then append "<space>00:00:00"... (1 Reply)
Discussion started by: machomaddy
1 Replies

8. Linux

How do I format a Date field of a .CSV file with multiple commas in a string field?

I have a .CSV file (file.csv) whose data are all enclosed in double quotes. Sample format of the file is as below: column1,column2,column3,column4,column5,column6, column7, Column8, Column9, Column10 "12","B000QRIGJ4","4432","string with quotes, and with a comma, and colon: in... (3 Replies)
Discussion started by: dhruuv369
3 Replies

9. Shell Programming and Scripting

Removing date field from the string

Hii I am trying to remove the date field from the following string. ODS_EPP_COVRG_STN_DETL_FILE_10032014.TXT. My output should be ODS_EPP_COVRG_STN_DETL_FILE.TXT I tried couple of things: echo ODS_EPP_COVRG_STN_DETL_FILE_10032014.TXT|sed 's/_*\.*//g' I am getting:... (9 Replies)
Discussion started by: skatpally
9 Replies

10. AIX

Sort by date field in AIX

I wanted to sort the below data on 4th field(comma seperator) based on month and date and time on AIX OS. Input data: 3,AJ,30 Jul 06:30,30 Jul 06:30 5,AJ,30 Jul 06:30,30 Jul 06:49 10,AJ,30 Jul 06:30,02 Jan 05:41 4,AJ,30 Jul 06:30,30 Jul 06:36 2,AJ,30 Jul 06:30,28 Jul 06:45 9,AJ,30 Jul... (2 Replies)
Discussion started by: Amit Joshi
2 Replies
GMMKTIME(3)								 1							       GMMKTIME(3)

gmmktime - Get Unix timestamp for a GMT date

SYNOPSIS
int gmmktime ([int $hour = gmdate("H")], [int $minute = gmdate("i")], [int $second = gmdate("s")], [int $month = gmdate("n")], [int $day = gmdate("j")], [int $year = gmdate("Y")], [int $is_dst = -1]) DESCRIPTION
Identical to mktime(3) except the passed parameters represents a GMT date. gmmktime(3) internally uses mktime(3) so only times valid in derived local time can be used. Like mktime(3), arguments may be left out in order from right to left, with any omitted arguments being set to the current corresponding GMT value. PARAMETERS
o $hour - The number of the hour relative to the start of the day determined by $month, $day and $year. Negative values reference the hour before midnight of the day in question. Values greater than 23 reference the appropriate hour in the following day(s). o $minute - The number of the minute relative to the start of the $hour. Negative values reference the minute in the previous hour. Values greater than 59 reference the appropriate minute in the following hour(s). o $second - The number of seconds relative to the start of the $minute. Negative values reference the second in the previous minute. Values greater than 59 reference the appropriate second in the following minute(s). o $month - The number of the month relative to the end of the previous year. Values 1 to 12 reference the normal calendar months of the year in question. Values less than 1 (including negative values) reference the months in the previous year in reverse order, so 0 is December, -1 is November, etc. Values greater than 12 reference the appropriate month in the following year(s). o $day - The number of the day relative to the end of the previous month. Values 1 to 28, 29, 30 or 31 (depending upon the month) refer- ence the normal days in the relevant month. Values less than 1 (including negative values) reference the days in the previous month, so 0 is the last day of the previous month, -1 is the day before that, etc. Values greater than the number of days in the relevant month reference the appropriate day in the following month(s). o $year - The year o $is_dst - Parameters always represent a GMT date so $is_dst doesn't influence the result. Note This parameter has been removed in PHP 7.0.0. RETURN VALUES
Returns a integer Unix timestamp. CHANGELOG
+--------+---------------------------------------------------+ |Version | | | | | | | Description | | | | +--------+---------------------------------------------------+ | 7.0.0 | | | | | | | $is_dst parameter has been removed. | | | | | 5.1.0 | | | | | | | As of PHP 5.1.0, the $is_dst parameter became | | | deprecated. As a result, the new timezone han- | | | dling features should be used instead. | | | | +--------+---------------------------------------------------+ EXAMPLES
Example #1 gmmktime(3) basic example <?php // Prints: July 1, 2000 is on a Saturday echo "July 1, 2000 is on a " . date("l", gmmktime(0, 0, 0, 7, 1, 2000)); ?> SEE ALSO
mktime(3), date(3), time(3). PHP Documentation Group GMMKTIME(3)
All times are GMT -4. The time now is 01:24 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy