LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-01-2005, 12:03 AM   #1
bigapple
LQ Newbie
 
Registered: Oct 2004
Location: Hangzhou.China
Distribution: Suse 9.3 | redhat 9.0 | Solaris 10
Posts: 29

Rep: Reputation: 15
about the date


hi,all
Is there a function like get_day_of_week(), the input is a string like this:
"01-Aug-2005" and the return is the Number 1 to 7 stand for the Monday to Sunday, for example,
Code:
      int rc;
      rc = get_day_of_week("01-Aug-2005");
      switch rc
          case 1: printf("Monday!");break;
           ....
          case 7: printf("Sunday!);break;
And the input date is not the current day,may be a day some years ago.


Now I want to konw is there a function in UNIX C, if not ,how can I write this function,,how can I convert the string to be a date !

any suggest will be helpful! thx!
 
Old 08-01-2005, 12:07 AM   #2
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
I guess you'd need to parse the string. Looking through the manpages for the various unix time functions, I don't find anything for string-to-date conversion, though I could just be missing it.
 
Old 08-01-2005, 12:28 AM   #3
bigapple
LQ Newbie
 
Registered: Oct 2004
Location: Hangzhou.China
Distribution: Suse 9.3 | redhat 9.0 | Solaris 10
Posts: 29

Original Poster
Rep: Reputation: 15
you are right, I have looked up the linux c reference,and haven't seen any function for 'string-to-date', but some functions for 'date-to-string'.
The openVMS old operation system,and it has the system call "lib$day_of_week", I want to make the openVMS program run on the UNIX,So I think I must write this function myself. Do you know the openVMS is a open source system or not?
 
Old 08-01-2005, 12:37 AM   #4
Matir
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
I have no idea, though the open in it sounds like it may be.
 
Old 08-01-2005, 04:09 AM   #5
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Re: about the date

Quote:
Originally posted by bigapple
Is there a function like get_day_of_week(), the input is a string like this:
"01-Aug-2005" and the return is the Number 1 to 7 stand for the Monday to Sunday,
Have a look at man 3 strptime. I think it's almost exactly what you need.
 
Old 08-04-2005, 10:05 PM   #6
bigapple
LQ Newbie
 
Registered: Oct 2004
Location: Hangzhou.China
Distribution: Suse 9.3 | redhat 9.0 | Solaris 10
Posts: 29

Original Poster
Rep: Reputation: 15
Thanks for Hko,
but I workstation is an AIX box,I have try 'man 3 strptime
',but it tells me the man page was not found or the strptime was not installed.
May be I will contact the Administrator of this box or try to find the source code of strptime.
 
Old 08-07-2005, 05:33 AM   #7
eddiebaby1023
Member
 
Registered: May 2005
Posts: 378

Rep: Reputation: 33
man ctime should point you in the right direction. mktime(3) lets you create a time structure and you can then get the bit(s) you want from that.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Start Date + Time Duration = End Date/Time calculator? ToBe Linux - General 3 09-26-2005 10:17 AM
system date tipsy Debian 5 08-07-2005 08:17 PM
Changing the date mad_ady Solaris / OpenSolaris 3 12-19-2004 03:50 PM
Change date mbayeb Linux - General 2 01-31-2003 08:57 AM
lastlog date does not match system date? jcmj Linux - Networking 6 10-22-2002 12:09 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:17 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration