New topic: 

ParseDate problem

<http://forums.realsoftware.com/viewtopic.php?t=46305>

         Page 1 of 1
   [ 5 posts ]                 Previous topic | Next topic          Author  
Message        torrid          Post subject: ParseDate problemPosted: Fri Dec 
21, 2012 11:24 am                                 
Joined: Sat Jun 04, 2011 8:29 am
Posts: 371                I have a place where user enters their birthdate... 
popdown select the month, enter the day, and year.  I have a conversion of 
month to digit so the string created is like "1/1/1950" which is then passed 
into ParseDate so we can do some date math.

On one customers machine it fails with "invalid birthdate" even though in the 
error popup it shows "1/1/1950".  

Turns out in his Date&Time in System Prefs he had changed the date format on 
his computer to be of the format:  Year-Month-Day  or "1950/1/1" so I think 
that preference change is barfing my ParseDate.

Sooooooo.... how do I detect such a system change?  i.e. what should I do 
differently in my code?      
_________________
Currently using:
Windows XP Pro SP3
Real Studio 2011 Release 4.3 Enterprise
and
Mac OS 10.7.4
Real Studio 2011 Release 4.3 Enterprise
(finally also compiled on Mac)  
                             Top                timhare          Post subject: 
Re: ParseDate problemPosted: Fri Dec 21, 2012 12:12 pm                         
Joined: Fri Jan 06, 2006 3:21 pm
Posts: 11908
Location: Portland, OR  USA                If you have the individual values, 
why would you need to use ParseDate?  Use the Date constructor that accepts 
month/day/year values.

year = //year entered by user
month = // month entered by user
day = //day entered by user
dim birthdate as Date = New Date(year, month, day)   
                             Top                elChupete          Post 
subject: Re: ParseDate problemPosted: Fri Dec 21, 2012 3:24 pm                  
               
Joined: Fri Jun 05, 2009 11:50 am
Posts: 323
Location: Hamburg, Germany                Had the same problem few years ago

Basic idea:

create a date object setting it to a known date (e.g. 1986-12-02)
get date.shortdate (returns a string of the known date according to users local 
settings (e.g. 12/02/1986  or 02/12/1986)
identify position of year, month, day in the string (as you know what is what)
put user entered date into a string of the same order as the date.shortdate 
format
parse the date to a dateobject.      
_________________
Best regards

Stefan

Mac OSX 10.8.1 on a MacBook Pro 2.66 GHz Intel Core i7/ RB Professional 2011 
Release 3  
                             Top                timhare          Post subject: 
Re: ParseDate problemPosted: Fri Dec 21, 2012 3:59 pm                         
Joined: Fri Jan 06, 2006 3:21 pm
Posts: 11908
Location: Portland, OR  USA                Quote:put user entered date into a 
string of the same order as the date.shortdate format
parse the date to a dateobject.
But why?  If you already know the month/day/year, why would you ever use 
ParseDate?   
                             Top                elChupete          Post 
subject: Re: ParseDate problemPosted: Fri Dec 21, 2012 4:27 pm                  
               
Joined: Fri Jun 05, 2009 11:50 am
Posts: 323
Location: Hamburg, Germany                timhare wrote:But why?  If you 
already know the month/day/year, why would you ever use ParseDate?


I won't, but in cases where one doesn't have the knowledge about month/day/year 
or need to know for whatever reason the local user date settings the idea would 
work      
_________________
Best regards

Stefan

Mac OSX 10.8.1 on a MacBook Pro 2.66 GHz Intel Core i7/ RB Professional 2011 
Release 3  
                             Top             Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 5 posts ]      
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

[email protected]

Reply via email to