HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- help in perl script
Operating System - HP-UX
1831185
Members
2942
Online
110021
Solutions
Forums
Categories
Company
Local Language
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2003 08:27 PM
05-22-2003 08:27 PM
My PERL script reports dates of 01/20/100. I used the printf format
$02d on the year value, but I still get year = 100.
Why am I having this problem?
$02d on the year value, but I still get year = 100.
Why am I having this problem?
Solved! Go to Solution.
2 REPLIES 2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2003 08:36 PM
05-22-2003 08:36 PM
Solution
You are getting dates of 01/20/100 because the localtime() return value
for year is currently 100 for the year 2000. The printf format for
decimal conversion (%02d) will prepend leading zeroes, but does not
truncate to two digits because that would modify the actual value.
'printf' has no truncation capability, even %02s prints the entire
string, so dealing with two digit dates is a problem that requires
coding. Subtracting 100 would yield 00, but for the year 99, that would
result in a year of -01.
To resolve your problem, use 4 digit year, just add 1900 to the year.
This applies to any language using the tm struct returned by functions
such as localtime()
PERL example
#Current date (MM/DD/YYYY)
$TI'DATE = join ('/', $TI'MON + 1, $TI'MDY, $TI'YR + 1900);
radhakrishnan
for year is currently 100 for the year 2000. The printf format for
decimal conversion (%02d) will prepend leading zeroes, but does not
truncate to two digits because that would modify the actual value.
'printf' has no truncation capability, even %02s prints the entire
string, so dealing with two digit dates is a problem that requires
coding. Subtracting 100 would yield 00, but for the year 99, that would
result in a year of -01.
To resolve your problem, use 4 digit year, just add 1900 to the year.
This applies to any language using the tm struct returned by functions
such as localtime()
PERL example
#Current date (MM/DD/YYYY)
$TI'DATE = join ('/', $TI'MON + 1, $TI'MDY, $TI'YR + 1900);
radhakrishnan
Negative thinking is a highest form of Intelligence
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2003 11:56 PM
05-22-2003 11:56 PM
Re: help in perl script
Although this explanation is correct, the main point is missing: unix dates are returned in seconds since 01-01-1970, and then converted to an array representing the date parts. In that list, the year is represented in years since 1900, hence year 100 stands for 2000.
Furthermore please do NOT use the syntax as described in the example, but use the `normal' syntax instead:
# Current date (DD-MM-YYYY)
my @d = localtime time;
my $date = sprintf "%02d-%02d-%04d", $d[3], $d[2] + 1, $d[5] + 1900;
$TI'DATE is the *OLD* (and depricated) way to write $TI::date. Please do *NOT* use that syntax unless you are trying to write obfuscated scripts.
Enjoy, have FUN! H.Merijn
Furthermore please do NOT use the syntax as described in the example, but use the `normal' syntax instead:
# Current date (DD-MM-YYYY)
my @d = localtime time;
my $date = sprintf "%02d-%02d-%04d", $d[3], $d[2] + 1, $d[5] + 1900;
$TI'DATE is the *OLD* (and depricated) way to write $TI::date. Please do *NOT* use that syntax unless you are trying to write obfuscated scripts.
Enjoy, have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP