- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Getting the day from a given date
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
Discussions
Discussions
Forums
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
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
тАО01-22-2003 08:12 AM
тАО01-22-2003 08:12 AM
Getting the day from a given date
is there a way to calculate the day if I've got a generated date.
For example :
If I have 030121 as a date, how do I calculate that the associated day is Tue ?
Cheers,
Enda
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-22-2003 08:34 AM
тАО01-22-2003 08:34 AM
Re: Getting the day from a given date
It's possible to calculte the day of the week in a C routine, COBOL or any other language.
Using Posix Shell I think it's not possible.
Do you need a routine in any of the above Language?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-22-2003 08:48 AM
тАО01-22-2003 08:48 AM
Re: Getting the day from a given date
To find them go to: http://www.cmve.net/~merijn/ and scroll all the way to the bottom to the section labeled "A. Clay Stephensons Date Hammer" and download either the shell version or perl version and make sure you chmod them so that they are executable.
To get full usage instructions do:
# ./caljd.sh -u
or
# ./caljd.pl -u
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-22-2003 08:56 AM
тАО01-22-2003 08:56 AM
Re: Getting the day from a given date
so
WKDAY=$(caljd.sh -w -o $(caljd.sh -y 2003 01 21))
echo "Day of the week: ${WKDAY}"
If you want a numerical value then drop the -w for 0 -> Sun; 6-> Sat. If you change -o to -O Tue becomes Tuesday and it also speaks other languages if you set the LOCALE.
Invoke as caljd.sh -u for full usage and many examples.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-22-2003 08:58 AM
тАО01-22-2003 08:58 AM
Re: Getting the day from a given date
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-22-2003 09:24 AM
тАО01-22-2003 09:24 AM
Re: Getting the day from a given date
read Date?"Enter date: "
Month=$(echo ${Date}|cut -c3-4)
Day=$(echo ${Date}|cut -c5-6)
Year=$(echo ${Date}|cut -c1-2)
Year=$(echo 20${Year})
cal ${Month} ${Year}
cal ${Month} ${Year}|
awk -vVar=${Day} '
{
split($0,ar," ")
if (ar[1] == Var) {print "Sunday"}
if (ar[2] == Var) {print "Monday"}
if (ar[3] == Var) {print "Tuesday"}
if (ar[4] == Var) {print "Wednesday"}
if (ar[5] == Var) {print "Thursday"}
if (ar[6] == Var) {print "Friday"}
if (ar[7] == Var) {print "Saturday"}
}'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-23-2003 10:34 PM
тАО01-23-2003 10:34 PM
Re: Getting the day from a given date
This works.
Cheers,
JW.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-23-2003 10:41 PM
тАО01-23-2003 10:41 PM
Re: Getting the day from a given date
The attachment works, but you'll need to change your date format.
Cheers,
JW.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО01-24-2003 01:52 AM
тАО01-24-2003 01:52 AM
Re: Getting the day from a given date
Divide the number of seconds since the epoch by 86400 (the number of seconds in a day),
then by 7. multiply the integer answer by 7 and subtract from the original number of days.
The number you have been returned will be the number of days to add to the Epoch Date, so if the value returned is 1, and the Epoch was on a Sunday, your day value is Monday (you can set up an array for returning the day name).
Just be aware, you will have to amend the epoch value for your TimeZone.
Share and Enjoy! Ian