Sponsored Content
Top Forums Shell Programming and Scripting change date format - 2009-10-30 -> today Post 302366926 by Scrutinizer on Friday 30th of October 2009 10:01:16 PM
Old 10-30-2009
Hi mrplow, try this :
Code:
for i in Today Tomorrow Monday Thursday Wednesday Thursday Friday Saturday Sunday; do
  sedstr="${sedstr}s/$(date -d $i +%Y-%m-%d)/$i/;"
done
myth_upcoming_recordings.pl --plain_text --text_format '%Y-%m-%d - %h:%i %A - %T - %S (%cN)\n' --heading "" |
while read date rest; do
  printf "%-10s %s\n" $(echo $date |sed "$sedstr") "$rest"
done

(not surprised you like the simpsons, mr. plow Smilie )

Last edited by Scrutinizer; 10-30-2009 at 11:11 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to Change the Format of a Date

Hi All, this is my second post, last post reply was very helpful. I have a data that has date in DD/MM/YYYY (07/11/2008) format i want to replace the backslash by a dot(.) so that my awk script can read it inside the C shell script that i have written. i want to change 07/11/2008 to... (3 Replies)
Discussion started by: asirohi
3 Replies

2. Shell Programming and Scripting

Date Format Change

Hi I have a date format in a variable as Mon Jan 11 03:35:59 2010. how do i change it to YYYYMMDD format (3 Replies)
Discussion started by: keerthan
3 Replies

3. Shell Programming and Scripting

Date Format Change

Hi, Please can I have some command to get yesterday in YYMMDD format? This will be used in ksh Thanks, (2 Replies)
Discussion started by: smalya
2 Replies

4. UNIX for Dummies Questions & Answers

Shell Scripts - shows today’s date and time in a better format than ‘date’ (Uses positional paramete

Hello, I am trying to show today's date and time in a better format than ‘date' (Using positional parameters). I found a command mktime and am wondering if this is the best command to use or will this also show me the time elapse since 1/30/70? Any help would be greatly appreciated, Thanks... (3 Replies)
Discussion started by: citizencro
3 Replies

5. Shell Programming and Scripting

How to change the date format

Hi Guys, Can someone help me on how to change the date format using sed or any unix command to give my desired output as shown below. INPUT FILE: 69372,200,20100122T17:56:02,2 53329,500,20100121T11:50:07,2 48865,100,20100114T16:08:16,2 11719,200,20100108T13:32:20,2 DESIRED... (2 Replies)
Discussion started by: pinpe
2 Replies

6. Shell Programming and Scripting

Date format change

Dear Friends, Need your help once again, I have a variable ( e.g. ${i}) whoch has date in MM/DD/YYYY (E.g. 12/31/2011) format. I want to change it to DD/MM/YYYY (e.g. 31/12/2011) format. Request you to guide me as we are unable to do the same. Thanks in advance Anu. (1 Reply)
Discussion started by: anushree.a
1 Replies

7. Shell Programming and Scripting

change date format

Hi, I have the variable "$date_update" in that form: 2011-12-31T13:00:09Z and I would like to change it to 31/12/2011 13:00:09 (Date and Time separated by a blank). Does anyone has a simple solution for that? (using Korn Shell) Cheers Jurgen (4 Replies)
Discussion started by: jurgen
4 Replies

8. Shell Programming and Scripting

Change the date format

Hi all, I have a file that every line starts with the date and time. The format is like YYYYMMDDHHMM and I woulk like to change it to MM/DD/YY<space>HH:MM. I tried to figure out a way to do it with sed, but I don't know how I could reorganize the digits of the first format. Does anyone have any... (1 Reply)
Discussion started by: geovas
1 Replies

9. Shell Programming and Scripting

Change the date format

Hi, I was looking for a script to change the date from one format to other. A search in the forum gave me the below script as a result. #! /bin/ksh format=YYYYMMDD YEAR=${format%????} DAY=${format#??????} MON=${format#$YEAR} MON=${MON%$DAY} echo $MON/$DAY/$YEAR I got it... (2 Replies)
Discussion started by: prithvirao17
2 Replies

10. UNIX for Dummies Questions & Answers

Change Date from one format to other

Hi I wish to change date from one format to another in unix. eg: INPUT DATE: 2013159 (YEAR & NUMBER OF DAY) OUTPUT DATE required: 20130608 (YYYYMMDD) how to do it ? Thanks in advance. (6 Replies)
Discussion started by: dashing201
6 Replies
ARRAY_UDIFF(3)								 1							    ARRAY_UDIFF(3)

array_udiff - Computes the difference of arrays by using a callback function for data comparison

SYNOPSIS
array array_udiff (array $array1, array $array2, [array $...], callable $value_compare_func) DESCRIPTION
Computes the difference of arrays by using a callback function for data comparison. This is unlike array_diff(3) which uses an internal function for comparing the data. PARAMETERS
o $array1 - The first array. o $array2 - The second array. o $value_compare_func - The callback comparison function. The comparison function must return an integer less than, equal to, or greater than zero if the first argument is considered to be respectively less than, equal to, or greater than the second. int callback (mixed $a, mixed $b) RETURN VALUES
Returns an array containing all the values of $array1 that are not present in any of the other arguments. EXAMPLES
Example #1 array_udiff(3) example using stdClass Objects <?php // Arrays to compare $array1 = array(new stdclass, new stdclass, new stdclass, new stdclass, ); $array2 = array( new stdclass, new stdclass, ); // Set some properties for each object $array1[0]->width = 11; $array1[0]->height = 3; $array1[1]->width = 7; $array1[1]->height = 1; $array1[2]->width = 2; $array1[2]->height = 9; $array1[3]->width = 5; $array1[3]->height = 7; $array2[0]->width = 7; $array2[0]->height = 5; $array2[1]->width = 9; $array2[1]->height = 2; function compare_by_area($a, $b) { $areaA = $a->width * $a->height; $areaB = $b->width * $b->height; if ($areaA < $areaB) { return -1; } elseif ($areaA > $areaB) { return 1; } else { return 0; } } print_r(array_udiff($array1, $array2, 'compare_by_area')); ?> The above example will output: Array ( [0] => stdClass Object ( [width] => 11 [height] => 3 ) [1] => stdClass Object ( [width] => 7 [height] => 1 ) ) Example #2 array_udiff(3) example using DateTime Objects <?php class MyCalendar { public $free = array(); public $booked = array(); public function __construct($week = 'now') { $start = new DateTime($week); $start->modify('Monday this week midnight'); $end = clone $start; $end->modify('Friday this week midnight'); $interval = new DateInterval('P1D'); foreach (new DatePeriod($start, $interval, $end) as $freeTime) { $this->free[] = $freeTime; } } public function bookAppointment(DateTime $date, $note) { $this->booked[] = array('date' => $date->modify('midnight'), 'note' => $note); } public function checkAvailability() { return array_udiff($this->free, $this->booked, array($this, 'customCompare')); } public function customCompare($free, $booked) { if (is_array($free)) $a = $free['date']; else $a = $free; if (is_array($booked)) $b = $booked['date']; else $b = $booked; if ($a == $b) { return 0; } elseif ($a > $b) { return 1; } else { return -1; } } } // Create a calendar for weekly appointments $myCalendar = new MyCalendar; // Book some appointments for this week $myCalendar->bookAppointment(new DateTime('Monday this week'), "Cleaning GoogleGuy's apartment."); $myCalendar->bookAppointment(new DateTime('Wednesday this week'), "Going on a snowboarding trip."); $myCalendar->bookAppointment(new DateTime('Friday this week'), "Fixing buggy code."); // Check availability of days by comparing $booked dates against $free dates echo "I'm available on the following days this week... "; foreach ($myCalendar->checkAvailability() as $free) { echo $free->format('l'), " "; } echo " "; echo "I'm busy on the following days this week... "; foreach ($myCalendar->booked as $booked) { echo $booked['date']->format('l'), ": ", $booked['note'], " "; } ?> The above example will output: I'm available on the following days this week... Tuesday Thursday I'm busy on the following days this week... Monday: Cleaning GoogleGuy's apartment. Wednesday: Going on a snowboarding trip. Friday: Fixing buggy code. NOTES
Note Please note that this function only checks one dimension of a n-dimensional array. Of course you can check deeper dimensions by using array_udiff($array1[0], $array2[0], "data_compare_func");. SEE ALSO
array_diff(3), array_diff_assoc(3), array_diff_uassoc(3), array_udiff_assoc(3), array_udiff_uassoc(3), array_intersect(3), array_inter- sect_assoc(3), array_uintersect(3), array_uintersect_assoc(3), array_uintersect_uassoc(3). PHP Documentation Group ARRAY_UDIFF(3)
All times are GMT -4. The time now is 04:34 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy