Hi ,
I want to convert a Date in any format into any other format i required.
Is there any built in function in PERL to do the date conversion in required format.
For exampe: If date is in 28-09-2006 i want to convert it to 09-22-2006 i.e.,(dd-mm-yyyy to mm-dd-yyyy)
Mainly i want to convert date in the format 28-sep-2006 to 09-22-2006 1.e.,(dd-mm-yyyy to mon-dd-yyyy).
Means i want to know is there any built in function in PERL like to_date function in ORACLE.
=========================
hi,
Use the time function to get current times in terms of seconds.
1 .$time_v = time;
Pass this result to gmtime function.
the syntax is as displayed below.
2 . ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isd st) = gmtime($time_v);
Converts a time as returned by the time function to an 9-element list with the time localized for the standard Greenwich time zone. Typically used as follows:
All list elements are numeric, and come straight out of the C `struct tm'. $sec, $min, and $hour are the seconds, minutes, and hours of the specified time. $mday is the day of the month, and $mon is the month itself, in the range 0..11 with 0 indicating January and 11 indicating December. $year is the number of years since 1900. That is, $year is 123 in year 2023. $wday is the day of the week, with 0 indicating Sunday and 3 indicating Wednesday. $yday is the day of the year, in the range 0..364 (or 0..365 in leap years). $isdst is always 0 .
Note that the $year element is not simply the last two digits of the year. If you assume it is then you create non-Y2K-compliant programs--and you wouldn't want to do that, would you?
The proper way to get a complete 4-digit year is simply:
$year += 1900;
$month=$month+1; # since months are represeneted like 0 to 11
finally
3. use sprint function to format the date according to your wish
let me know if you still faces difficulties.