![]() |
|
#1
|
|||
|
|||
Trying to convert a Date StringHi,
I am wondering if anyone could help me with a conversion. I have a date that is in the format of Code:
I need to add one day to it. Does anyone have any idea? Thanks, |
|
#2
|
|||
|
|||
Re: Trying to convert a Date Stringwell, since you know the format of the string, you can easily parse it into a number (usually computers represent date/time as offset since Jan 1, 1970). One question is with single-digit days, will the format be 1-JAN-1970 or 01-JAN-1970?
In any case, I would probably use a stringstream. Research these. You would declare the stringstream, output the string date to it, and then extract (>> operator) the day, month, and year. Then you could add one to the day, but make sure to handle cases where it spills over into the next month (you'll need to algorithm-ize "30 days hath september..." and leap years (a year is a leap year if it's divisible by 4, but not if it's divisible by 100 unless it's also divisible by 400; have fun concocting that if condition)). See how far you can get and post back here if you need further assistance. |
|
#3
|
|||
|
|||
Re: Trying to convert a Date StringHi,
OK I have been able to parse my string, and then convert the date into an int. Is there a way I can use some sort of date class and pass in my parameters?? CPP / C++ / C Code:
Thanks, Last edited by LuciWiz : 07-May-2006 at 10:11.
Reason: Please insert your C++ code between [c++] & [/c++] tags
|
|
#4
|
||||
|
||||
Re: Trying to convert a Date StringQuote:
__________________
Got a cough? Go home tonight and eat a whole box of Ex-Lax. Tomorrow, you'll be afraid to cough. -- Pearl Williams |
|
#5
|
|||
|
|||
Re: Trying to convert a Date StringHi,
Yes, actually for my debugging, I simply added a one to the number. However, as suggested, there are a few things to take account for, and using a bunch of if -else statements or quite a few nested for loops, I was hoping there was a cleaner way. Thanks! |
Recent GIDBlog
Toyota - 2008 November Promotion by Nihal
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Read a .html file, check that file for links | salemite | C Programming Language | 10 | 17-Jan-2008 08:56 |
| Convert date string to number | bjvar | C Programming Language | 3 | 03-Apr-2006 14:32 |
| variables return to previous value after i try to set them | nasaiya | MS Visual C++ / MFC Forum | 2 | 14-Jun-2005 01:43 |
| Help wit my source code compiler errors | Krandygrl00 | C++ Forum | 1 | 06-Jun-2005 09:14 |
| Converting string to float | CT++ | C++ Forum | 2 | 10-May-2005 12:29 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The