10-01-2015
Thanks balajesuri.
It works perfectly. I did go through the usage of POSIX/ strftime to understand why you have used -1 for $y[1] (Month) and was able to get the answer.
Thanks again for your help.
![Smilie Smilie](https://www.unix.com/images/smilies/smile.gif)
10 More Discussions You Might Find Interesting
1. Shell Programming and Scripting
I want to change a date from format dd-mmm-yyyy to mm/dd/yyyy. Is there a way to do this with sed or do you have to write a case statement to convert JAN to 01? Thanks (9 Replies)
Discussion started by: stringzz
9 Replies
2. Shell Programming and Scripting
How to convert the date field from dd/mm/yyyy to yyyy/mm/dd in unix
my script will generate text file which have two fields
one is date and another is name of the server for example this is sample date which I have to sort based on older to newer date the problem is when I found out sort will... (4 Replies)
Discussion started by: pareshan
4 Replies
3. Shell Programming and Scripting
Can't find out how to get the day of the week from a given date, anyone got a code snippet that could help please?
Ta!! (4 Replies)
Discussion started by: couponmeup
4 Replies
4. Shell Programming and Scripting
(Attention: Green PHP newbie !)
I have an online inquiry form, delivering a date in the form yyyy/mm/dd to my feedback form. If the content passes several checks, the form sends an e-mail to me. All works fine. I just would like to receive the date in the form dd/mm/yyyy. I tried with some code,... (6 Replies)
Discussion started by: keyboarder
6 Replies
5. Shell Programming and Scripting
I am trying to get the string containing date - in a specfic format actually, although I think that part is inconsequencial - 1110226^1110226^1110226^1110226^1110226 - through echo or printf or in some other way - created within a cront job and passed as a parameter to a perl script.
Now, I know... (3 Replies)
Discussion started by: v8625
3 Replies
6. Shell Programming and Scripting
Hello,
I am writing a script that parses different logs and produces one. In the source files, the date is in DD MM YYYY HH24:MI:SS format. In the output, it should be in DD MON YYY HH24:MI:SS (ie 25 Jan 2010 16:10:10)
To extract the dates, I am using shell substrings, i.e.:
read line
... (4 Replies)
Discussion started by: Adamm
4 Replies
7. Shell Programming and Scripting
Hi,
How can I convert day of year value in format(yy,doy) to normal formatted (dd.mm.yyyy) string also all of them with awk or awk system function?
in_file.txt
---------
12,043
12,044
12,045
12,046
out_file.txt
----------
12.02.2012
13.02.2012
14.02.2012
15.02.2012
imagine... (5 Replies)
Discussion started by: kocaturk
5 Replies
8. Shell Programming and Scripting
Hi I have a problem with Date format in my code.
1st I am trying to convert today's date to yesterday's using
YESTERDAY3=`perl -e '@y=localtime(time()-86400); printf "%04d/%02d/%02d",$y+1900,$y+1,$y;$y;'`
And once it is done I am trying to using the yesterday date in a grep command to... (3 Replies)
Discussion started by: nithinankam
3 Replies
9. UNIX for Dummies Questions & Answers
I've seen a lot of posts on this and have tried the following:
echo 1257000000| perl -e '($d,$m,$y)=(localtime(time-86400));$m+=1;$y+=1900;printf "$y/$m/$d\n";'
But I am unable to convert a past Epoch date into a format such as YYYY/MM/DD or MM/DD/YYYY.
I am using bash and don't know... (4 Replies)
Discussion started by: newbie2010
4 Replies
10. Shell Programming and Scripting
I am getting output of YYYY-MM-DD and want to change this to DD/MM/YYYY.
When am running the query in 'Todd' to_date(column_name,'DD/MM/YYYY') am getting the required o/p of DD/MM/YYYY, But when am executing the same query(Netezza) in linux server(bash) am getting the output of YYYY-MM-DD
file... (3 Replies)
Discussion started by: Roozo
3 Replies
STRPTIME(3) 1 STRPTIME(3)
strptime - Parse a time/date generated withstrftime(3)
SYNOPSIS
array strptime (string $date, string $format)
DESCRIPTION
strptime(3) returns an array with the $date parsed, or FALSE on error.
Month and weekday names and other language dependent strings respect the current locale set with setlocale(3) ( LC_TIME).
PARAMETERS
o $date (
string) - The string to parse (e.g. returned from strftime(3)).
o $format (
string) - The format used in $date (e.g. the same as used in strftime(3)). Note that some of the format options available to strf-
time(3) may not have any effect within strptime(3); the exact subset that are supported will vary based on the operating system
and C library in use. For more information about the format options, read the strftime(3) page.
RETURN VALUES
Returns an array or FALSE on failure.
The following parameters are returned in the array
+-----------+---------------------------------------------------+
|parameters | |
| | |
| | Description |
| | |
+-----------+---------------------------------------------------+
| | |
| "tm_sec" | |
| | |
| | Seconds after the minute (0-61) |
| | |
| | |
| "tm_min" | |
| | |
| | Minutes after the hour (0-59) |
| | |
| | |
|"tm_hour" | |
| | |
| | Hour since midnight (0-23) |
| | |
| | |
|"tm_mday" | |
| | |
| | Day of the month (1-31) |
| | |
| | |
| "tm_mon" | |
| | |
| | Months since January (0-11) |
| | |
| | |
|"tm_year" | |
| | |
| | Years since 1900 |
| | |
| | |
|"tm_wday" | |
| | |
| | Days since Sunday (0-6) |
| | |
| | |
|"tm_yday" | |
| | |
| | Days since January 1 (0-365) |
| | |
| | |
|"unparsed" | |
| | |
| | the $date part which was not recognized using the |
| | specified $format |
| | |
+-----------+---------------------------------------------------+
EXAMPLES
Example #1
strptime(3) example
<?php
$format = '%d/%m/%Y %H:%M:%S';
$strf = strftime($format);
echo "$strf
";
print_r(strptime($strf, $format));
?>
The above example will output something similar to:
03/10/2004 15:54:19
Array
(
[tm_sec] => 19
[tm_min] => 54
[tm_hour] => 15
[tm_mday] => 3
[tm_mon] => 9
[tm_year] => 104
[tm_wday] => 0
[tm_yday] => 276
[unparsed] =>
)
NOTES
Note
This function is not implemented on Windows platforms.
Note
Internally, this function calls the strptime() function provided by the system's C library. This function can exhibit noticeably
different behaviour across different operating systems. The use of date_parse_from_format(3), which does not suffer from these
issues, is recommended on PHP 5.3.0 and later.
Note
"tm_sec" includes any leap seconds (currently upto 2 a year). For more information on leap seconds, see the Wikipedia article on
leap seconds.
Note
Prior to PHP 5.2.0, this function could return undefined behaviour. Notably, the "tm_sec", "tm_min" and "tm_hour" entries would
return undefined values.
SEE ALSO
checkdate(3), strftime(3), date_parse_from_format(3), DateTime.createFromFormat(3).
PHP Documentation Group STRPTIME(3)