Sponsored Content
Top Forums Shell Programming and Scripting get yesterday in yyyymmdd format Post 78165 by matrixmadhan on Saturday 16th of July 2005 04:35:33 AM
Old 07-16-2005
Code:
date | awk '{printf"%4d%2d%2d\n",$6,$2,($3-1)}' | sed 's/ /0/g'

i dont think the above one would work... the second parameter ($2) is displayed as such for month .. which is string format (ex: jul) but required output is in numeric format (07 - for jul)


here is the modification of the aboe one:

date '+%y:%m:%d' | awk -F":" '{printf"20%2d%2d%2d\n",$1,$2,($3-1)}' | sed 's/ /0/g'
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

get yesterday date in yyyymmdd format

I would like to know how I could get a yesterday date in yyyymmdd e.g. today is 20011109, and I would like to get 20011108. Thank you!:confused: (2 Replies)
Discussion started by: hk_newbie
2 Replies

2. HP-UX

How can i get the yesterday's date in YYYYMMDD format

How can i get the yesterday's date in YYYYMMDD format??? (4 Replies)
Discussion started by: prasadsr
4 Replies

3. UNIX for Dummies Questions & Answers

Format date from MM/DD/YYYY to YYYYMMDD

I have a file with some date columns in MM/DD/YYYY format: SMPBR|DUP-DO NOT USE|NEW YORK||16105|BA5270715|6/6/2007 |MWERNER|109||||JOHN||SMITH|MD|72211118||||||74559|21 WILMINGTON RD||D|11/6/2003|SL# MD CONTACT-LIZ RICHARDS|||0|Y|N||1411458| And I want to convert the date format to: ... (5 Replies)
Discussion started by: ChicagoBlues
5 Replies

4. Shell Programming and Scripting

convert date format YYYYMMDD to MM/DD/YYYY

In my shell script i have a variable which stores date in the format of YYYYMMDD. Is there any way to format this value to MM/DD/YYYY. Thanks. (8 Replies)
Discussion started by: nasirgondal
8 Replies

5. Shell Programming and Scripting

Find the next day from 20100303 (YYYYMMDD format)

Hi , i have doubt in bash shell script.. for example my file name is sampledate.sh given command = ./sampledate.sh -d 20100303 -f karthi how to find the next day from 20100303 (YYYYMMDD format) After getting the next day ,changed date and -f argument value will be sent to one java class. ... (13 Replies)
Discussion started by: karthinvk
13 Replies

6. Shell Programming and Scripting

Change the date format from mmddyyyy to yyyymmdd

How do I change the date format from mmddyyyy to yyyymmdd in PERL. Can any one help me please. (3 Replies)
Discussion started by: thankful123
3 Replies

7. Solaris

Date after 5 dates in YYYYMMDD format

Hi Experts, How to get date 5 days after current date in YYYYMMDD format? How do we compare date in YYYYMMDD format? Thanks (1 Reply)
Discussion started by: needyourhelp10
1 Replies

8. Shell Programming and Scripting

Validating date in yyyymmdd format using PERL

Hi all, i had a code where in user will enter a date in yyyymmdd format.. i didnt use any validation for the date and now the problem is if a user enters date instead of month after year it is proceeding with the code.. like if the date is 20120426 and if the user enters 20122604 it... (4 Replies)
Discussion started by: smarty86
4 Replies

9. Shell Programming and Scripting

Date format to be changed from DDMMYYYY to YYYYMMDD

My requirement is:- there will be files at a location each day with the date format DDMMYYYY. Novawise_Activity_Call_Notes_04022013.txt Novawise_Activity_Inbound_04022013.txt Novawise_Activity_Inbound_05022013.txt Novawise_Activity_Call_Notes_05022013.txt... (8 Replies)
Discussion started by: djrulz123
8 Replies

10. Shell Programming and Scripting

How to conver YYYYMMDD to MJD format?

I would like to convert YYYYMMDD to MJD format for eg 20041223 converted to 53362 in MJD format i got logic from javascript to covert it to MJD which is long enough function YMDtoMJD (year, month, day) { var year; var monthi var day; var yr = Math.floor (year); ... (1 Reply)
Discussion started by: mandalmanas24
1 Replies
printf(3int)															      printf(3int)

Name
       printf, fprintf, sprintf - print formatted output

Syntax
       #include <stdio.h>

       int printf ( format [, arg ] ...  )
       char *format;

       int fprintf ( stream, format [, arg ] ...  )
       FILE *stream;
       char *format;

       int sprintf ( s, format [, arg ] ...  )
       char *s, *format;

Description
       The  international functions and are similar to the standard I/O functions. The difference is that the international functions allow you to
       use the %digit$ conversion character in place of the % character you use in the standard I/O functions. The digit is a decimal digit n from
       1 to 9.	The international functions apply conversions to the n th argument in the argument list, rather than to the next unused argument.

       You can use the % conversion character in the international functions.  However, you cannot mix the % conversion character with the %digit$
       conversion character in a single call.

       You can indicate a field width or precision by an asterisk (*) instead of a digit string in format  strings  containing	the  %	conversion
       character.  If you use an asterisk, you can supply an integer arg that specifies the field width or precision. In format strings containing
       the %digit$ conversion character, you can indicate field width or precision by the sequence *digit$.  You use a decimal digit from 1  to  9
       to indicate which argument contains an integer that specifies the field width or precision.

       The conversion characters and their meanings are identical to

       You must use each digit argument at least once.

       In  all	cases, the radix character uses is defined by the last successful call to category If category has not been called successfully or
       if the radix character is undefined, the radix character defaults to a period (.).

   International Environment
       LC_NUMERIC     If this environment is set and valid, uses the international language database named in the definition  to  determine  radix
		      character rules.

       LANG	      If  this environment variable is set and valid uses the international language database named in the definition to determine
		      collation and character classification rules.  If is defined, its definition supercedes the definition of LANG.

Examples
       The following example illustrates using an argument to specify field width:
       printf ("%1$d:%2$.*3$d:%4$.*3$d
",
			   hour, min, precision, sec);
       The format string *3$ indicates that the third argument, which is named precision, contains the integer field width specification.

       To print the language independent date and time format use the following statement:
       printf (format, weekday, month, day, hour, min);
       For American use, format could be a pointer to the following string:
       "%1$s,  %2$s %3$d, %4$d:%5$.2d
"
       This string gives the following date format:
       Sunday, July 3, 10:02
       For use in a German environment, format could be a pointer to the following string:
       "%1$s, %3$d. %2$s, %4$d:%5$.2d
"
       This string gives the following date format:
       Sonntag, 3. Juli, 10:02

Return Values
       and return zero for success and EOF for failure.  The subroutine returns its first argument for success and EOF for failure.

       In the System V and POSIX environments, and return the number of characters transmitted for success.  The function ignores the null  termi-
       nator () when calculating the number of characters transmitted.  If an output error occurs, these routines return a negative value.

See Also
       intro(3int), setlocale(3), scanf(3int), printf(3s), putc(3s), scanf(3s), stdio(3s)
       Guide to Developing International Software

																      printf(3int)
All times are GMT -4. The time now is 07:59 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy