_Kurt Posted March 18, 2007 Share Posted March 18, 2007 (edited) Perhaps try a different approach to this, instead of splitting the string by "\" 's, _StringReverse it for the datediff. _DateDiff("y",_StringReverse($date), _NowCalc()) (untested) Something like that Kurt Edited March 18, 2007 by _Kurt Awaiting Diablo III.. Link to comment Share on other sites More sharing options...
Diana (Cda) Posted January 28, 2008 Share Posted January 28, 2008 Hi! I just found this thread and it's something that I need. But I'm having trouble with the translation and, because of that I think, in getting it to work. Here's what I think it should be in English: #include <Date.au3> $input = InputBox("Age Calculator","Year of birth:") If StringRegExp($input,"[^-0-9]",0) Then ; <-- geeft 1 als er een ander character dan een - of een cijfer in staat MsgBox(0,"","The date eis in the wrong format.") Else $date = StringSplit($input,"-") $test = _DateDiff("y",_StringReverse($date), _NowCalc()) MsgBox(0,"",$test) EndIf I get this error - "Unknown function name", which I don't know how to fix. Thanks! Link to comment Share on other sites More sharing options...
GEOSoft Posted January 28, 2008 Share Posted January 28, 2008 Hi! I just found this thread and it's something that I need. But I'm having trouble with the translation and, because of that I think, in getting it to work. Here's what I think it should be in English: #include <Date.au3> $input = InputBox("Age Calculator","Year of birth:") If StringRegExp($input,"[^-0-9]",0) Then ; <-- geeft 1 als er een ander character dan een - of een cijfer in staat MsgBox(0,"","The date eis in the wrong format.") Else $date = StringSplit($input,"-") $test = _DateDiff("y",_StringReverse($date), _NowCalc()) MsgBox(0,"",$test) EndIf I get this error - "Unknown function name", which I don't know how to fix. Thanks! It looks like that code forgot to #include <string.au3> for the _StringReverse() function. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
weaponx Posted January 28, 2008 Share Posted January 28, 2008 What language is your "database"? SQL, MySQL??? You should be filtering out the age in your query server side, not client side. Link to comment Share on other sites More sharing options...
Diana (Cda) Posted January 28, 2008 Share Posted January 28, 2008 What language is your "database"? SQL, MySQL??? You should be filtering out the age in your query server side, not client side.Oh, you lost me. Maybe that's why I'm having trouble. I was trying to use this straight as a way to calculate age. i.e., if I typed in 1962, the result would be "45" for 45 years of age. My mistake.Surprisingly, there are no age calculators coming up in the forum. This was the only message related to calculating age.What one would use to just calculate age by typing in a year?Thanks. Link to comment Share on other sites More sharing options...
Diana (Cda) Posted January 28, 2008 Share Posted January 28, 2008 It looks like that code forgot to #include <string.au3> for the _StringReverse() function.Just saw your response.Yes, this helped but now I get a "0" in the end result box. As I just mentioned in my earlier post, perhaps I misunderstood what the code above is supposed to do. But looking at it, even though it seems to be in German, it appeared that it would do what I'd like it to do, namely calculate age. Perhaps I'm wrong, though?Thx. Link to comment Share on other sites More sharing options...
GEOSoft Posted January 28, 2008 Share Posted January 28, 2008 Just saw your response. Yes, this helped but now I get a "0" in the end result box. As I just mentioned in my earlier post, perhaps I misunderstood what the code above is supposed to do. But looking at it, even though it seems to be in German, it appeared that it would do what I'd like it to do, namely calculate age. Perhaps I'm wrong, though? Thx. The wrong data was being sent to _DateDiff() The following does work except for accuracy because I used /01/01 for the missing data. #include <Date.au3> #include <string.au3> $input = InputBox("Age Calculator","Year of birth:") If StringRegExp($input,"[^-0-9]",0) Then ; <-- geeft 1 als er een ander character dan een - of een cijfer in staat MsgBox(0,"","The date is in the wrong format.") Else ;$date = StringSplit($input,"-") ;$test = _DateDiff("y",_StringReverse($date), _NowCalc()) MsgBox(0, "TEST", $Input & @CRLF & _NowCalc()) $test = _DateDiff("y",$input & "/01/01 00:00:00", _NowCalc()) MsgBox(0,"",$test) EndIf George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
Diana (Cda) Posted January 29, 2008 Share Posted January 29, 2008 The wrong data was being sent to _DateDiff() The following does work except for accuracy because I used /01/01 for the missing data. #include <Date.au3> #include <string.au3> $input = InputBox("Age Calculator","Year of birth:") If StringRegExp($input,"[^-0-9]",0) Then; <-- geeft 1 als er een ander character dan een - of een cijfer in staat MsgBox(0,"","The date is in the wrong format.") Else ;$date = StringSplit($input,"-") ;$test = _DateDiff("y",_StringReverse($date), _NowCalc()) MsgBox(0, "TEST", $Input & @CRLF & _NowCalc()) $test = _DateDiff("y",$input & "/01/01 00:00:00", _NowCalc()) MsgBox(0,"",$test) EndIfYes, I see what you mean with regards to accuracy. It isn't always going to be accurate with regards to birthday. i.e., it's saying I'm 46 since we're now in 2008 when I won't be 46 for another 2 months. Hmmm, this isn't going to work as is and I already have freewares to do the same thing. I just wanted something much more streamlined. Frankly, I took a look at AI's calendar control and I don't like it. And I don't know enough to do something much simpler and quicker, having a pulldown for each component of the birthday like how the months show up in the calendar control. What I mean by that is, rather than typing a date, there'd be a pulldown for the month (so that we'd click and then move pointer down to "November", then click), and then clicked on any number in a pulldown from 1 to 31, and then choose a date from a pulldown, too. So giving up on this one for now. I don't yet have enough knowledge to work this one out by myself. I'll just have to make due with my cumbersome freewares. Thanks! Link to comment Share on other sites More sharing options...
GEOSoft Posted January 29, 2008 Share Posted January 29, 2008 Yes, I see what you mean with regards to accuracy. It isn't always going to be accurate with regards to birthday. i.e., it's saying I'm 46 since we're now in 2008 when I won't be 46 for another 2 months. Hmmm, this isn't going to work as is and I already have freewares to do the same thing. I just wanted something much more streamlined. Frankly, I took a look at AI's calendar control and I don't like it. And I don't know enough to do something much simpler and quicker, having a pulldown for each component of the birthday like how the months show up in the calendar control.What I mean by that is, rather than typing a date, there'd be a pulldown for the month (so that we'd click and then move pointer down to "November", then click), and then clicked on any number in a pulldown from 1 to 31, and then choose a date from a pulldown, too.So giving up on this one for now. I don't yet have enough knowledge to work this one out by myself. I'll just have to make due with my cumbersome freewares.Thanks! If you look at _DateDiff() in the help file you will see the format for entering a date string. Inputing the data in the proper format will give you better accuracy. Right to the second if everything is there. George Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.*** The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number. Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else. "Old age and treachery will always overcome youth and skill!" Link to comment Share on other sites More sharing options...
Diana (Cda) Posted February 10, 2008 Share Posted February 10, 2008 If you look at _DateDiff() in the help file you will see the format for entering a date string. Inputing the data in the proper format will give you better accuracy. Right to the second if everything is there.<sigh> I don't get it. When I enter anything other than a year, it tells me I've put in the wrong date format, yet nothing else works!!! There is no prompt on how to enter the date, so that doesn't help, and I can't tell from the script or from _DateDiff in help file. You know, the help file is really great to have but it's often incomprehensible to us. I spend a lot of time studying it and working code around, yet half the time can't get things to work. That is what is happening here again. Nothing other than the actual year seems to work!So there's the problem in a nutshell, if I enter my birthday year, 1962, it accepts the data but tells me the age is 46. Excuse me, I won't be 46 for another month and a half! I don't know about anyone else, but I do _not_ like to be older than I absolutely have to be!! <lol>So whatever is needed to fix this, after another half an hour+ of mucking around, it still doesn't work and is giving the wrong data.So, may look at it again later but not right now, as I'm no closer to a solution. These sessions have a tendency to give me a headache! <g>Thanks. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now