- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Convert Any Date Into A 3-digit Decimal Number
Categories
Company
Local Language
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
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
Community
Resources
Forums
Blogs
- 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
04-06-2004 08:23 AM
04-06-2004 08:23 AM
Convert Any Date Into A 3-digit Decimal Number
I need to convert any date into a 3 digit decimal number for scripting purposes.
Is there an HP-UX command that can do that?
Thanks,
Suren S.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2004 08:37 AM
04-06-2004 08:37 AM
Re: Convert Any Date Into A 3-digit Decimal Number
DAYS=$(date '+%j')
echo "Days = ${DAYS}"
will do it.
but if you want to be able to input the date, say in MO DAY YEAR order and the number you desire is a number in the range 1-366 then this should do it:
#!/usr/bin/sh
typeset -i10 MO=${1}
typeset -i10 DA=${2}
typeset -i10 YR=${3}
shift 3
typeset -i10 DAYS=$(($(caljd.sh ${MO} ${DA} ${YR} - $(caljd.sh 1 1 ${YR}) + 1))
echo "Days = ${DAYS}"
You can also get a nice ordered number (though not 3 digits) with
caljd.sh MO DAY YR
This would yield the number of days since 4712 BCE.
Invoke as caljd.sh -u for full usage; you might also choose to simply yank out the cal_jdate function and use it.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2004 09:29 AM
04-06-2004 09:29 AM
Re: Convert Any Date Into A 3-digit Decimal Number
typeset -i10 MO=${1}
typeset -i10 DA=${2}
typeset -i10 YR=${3}
shift 3
typeset -i10 DAYS=$(($(caljd.sh ${MO} ${DA} ${YR} - $(caljd.sh 1 1 ${YR}) + 1))
typeset -Z3 ZDAYS=${DAYS}
echo "Days = ${ZDAYS}"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2004 09:34 AM
04-06-2004 09:34 AM
Re: Convert Any Date Into A 3-digit Decimal Number
Well if all you're looking for is the day of the year in a 3-digit output, the date command alone can do that - as follows:
date +%j
will give you that.
man date for details.
HTH,
Jeff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2004 09:39 AM
04-06-2004 09:39 AM
Re: Convert Any Date Into A 3-digit Decimal Number
My goal is to be able to convert any date into a 3 or 4 digit number.
There is a missing ')' in the script. Any idea where it should be?
When I ran this script by assigning a ) at the end it hung my system.
Thanks,
Suren
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2004 09:44 AM
04-06-2004 09:44 AM
Re: Convert Any Date Into A 3-digit Decimal Number
typeset -Z3 ZDAYS=${DAYS}
The missing 'paren' was after the first ${YR}, the above should work.
You really need to beter define your problem because it is not at all clear how you want to handle year boundaries.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-06-2004 07:48 PM
04-06-2004 07:48 PM
Re: Convert Any Date Into A 3-digit Decimal Number
if you consider a period of a few years, it is impossible to convert a date to a 3 digit number without having duplicates (two dates having the same 3 digit number (or 4 digits).
It seems to me a minimum requirement that all dates are given a unique number.
So indeed you should refine your question.
JP.