Strange date
Hi,
I have a strange problem with date.
I retrieved a value from another application as string which is supposed to be a date. But when I change it to date, it turns upside down!
For example, the value I retrieved is 20-09-04 where 20 is day, 09 is month and 04 is year. When I store it in a date variable, it turns to 9/4/2020. I even tried formatting it to "dd/mm/yy", but still the same. Please help.
Thanks
[447 byte] By [
shers] at [2007-11-11 8:51:17]

# 1 Re: Strange date
Q. -what do you have in your Regional & Language Settings" - English (United States) or (United Kingdom) or (Australian) etc? - these treat dates in different ways.
BTW Try format("your date", "dd mmm yyyy") and see what you get.
gupex at 2007-11-11 17:24:53 >

# 2 Re: Strange date
But since this is a network program, everybody will have different settings. So I wish to standardize the date regardless of the system date format.
Thanks
shers at 2007-11-11 17:25:55 >

# 3 Re: Strange date
What syntax did you use to try and force the format?
# 4 Re: Strange date
shers,while storing a date in a db,for example,it's preferable to store the date in the short-date format(ex. - 20/apr/06) & then when you retrieve it you know exactly what it is - as opposed to wondering whether it's in the American or English format.
By default the Windows environment interprets a date in the numeric format(for ex. - 11/09/06) as the American format.Therefore,if at all you want to store date in the numeric format & if you're prefer the English format then you must store the date(in your application) by exchanging the places of the day & month(for ex. - from 11/09/06(English) to 09/11/06(American)).Now,when you retrieve the same & want to display it in the English format repeat the same process - exchanging the places of the day & month.
In your ex.,the date "20-09-04 " is interpreted as American - but invalid!Because 20 doesn't represent any month.Therefore,it gets interpreted by the system as a year.And you get the result - 9/4/2020.
# 5 Re: Strange date
I disagree with softraj: you should not store dates as strings in your database. You should store them as dates, which have no implicit format, then format them as desired when you display them to the user.
Shers: Date variables have no format until you convert them to strings. Please post a small code sample that demonstrates the behavior you describe.
# 6 Re: Strange date
...you should not store dates as strings in your database....
absolutely! even better, store them in UT (universal time) so they are region-independent, in case the same database is used in more than one time zone
Marco
mstraf at 2007-11-11 17:30:04 >

# 7 Re: Strange date
phil weber,your disagreement with me is not that convincing without any furthur elaboration.Besides,in Oracle the default & the only format to store date value is the short-date format which is the easiest.Why take the trouble of deciphering whether a date value in a db is in the American or English format & then take the necessary action?
# 8 Re: Strange date
softraj: My point is that if you store the date in the database as a date rather than as a string, you don't HAVE to decipher anything. Consider the following pseudo-code. If we store date values as strings, we must:
' Get date input from user
' Determine whether user entered date in U.S. or European format
' Convert date to dd-mmm-yyyy format
' Store in database
Now it's time to retrieve the date and display it to the user:
' Retrieve date from database; it is a string in dd-mmm-yyyy format
' Determine whether user is American or European
' Parse string into day, month, year values
' Rearrange values into user's preferred format
If we store dates as dates instead of strings, we can do this:
' Get date input from user
' Assign input to Date-type variable; assignment automatically parses input based on user's regional settings and correctly determines year, month and day values
' Insert date value into database
To display:
' Retrieve date value from database
' Use Format function (VB has one built in) to format date according to user's regional settings
See how much less work you have to do in the latter case?
# 9 Re: Strange date
Phil Weber,your explanations are funny.
First thing first,date values,if in the numeric format(04/05/06),are auto interpreted as that of American format & stored as such.Therefore,your comment that "assignment automatically parses input based on user's regional settings and correctly determines year, month and day values" falls flat against the default American format.
And you do not've to "Determine whether user entered date in U.S. or European format" because as & when user enters the date value(numerically) it'll be parsed as per the short-date format(dd/mmm/yy or mmm/dd/yy) & stored as such - irrespective of the Regional Settings.And why "Parse string into day, month, year values" after retrieving the data or "Rearrange values into user's preferred format"?You simply display what is stored.And what was stored is the user-format,what else.
Parsing is needed only if the date value is stored in the numeric(American) format - precisely as I'd mentioned in my 1st posting.
# 10 Re: Strange date
sorry softraj but I did not follow you.
In US, I enter today's date as 6/8/06, as a String. If I store it in the database as string, it will be stored as "6/8/06" (no changes).
Now, I buddy of mine in Italy opens the same record and what he/she gets is August 6, 2006 (because the String is converted using European standards). And that is wrong.
If, on the other hand, I convert the String as a Date, it will be stored as a Date (internal format, no language dependent). The pc of my Italian buddy will convert correctly to June 8, 2006
Marco
mstraf at 2007-11-11 17:34:10 >

# 11 Re: Strange date
Ok mstraf,this is what probably has happened with your Italian buddy & in his machine:
Regional setting: dd/mmm/yy
Stored date value: 6/8/06 (as string)
In the code: Format("6/8/06","mmmm dd, yyyy")
Result: August 6, 2006
And this is a valid result in keeping with the regional setting.The 8 in the date value is interpreted as August because both 8 & "mmm" exists in the middle position.
But if you store date in the numeric format(6/8/06) it is treated as the American format in all Windows platform.Now lets use the above technique:
Regional setting:m/d/yy (default American format)
Stored date value:6/8/06 (date type)
In the code:Format("6/8/06","mmmm dd, yyyy")
Result: June 8, 2006
Have I made myself clear?
# 12 Re: Strange date
...But if you store date in the numeric format(6/8/06) it is treated as the American format in all Windows platform...
I still do not understand. As you just said, 6/8/06 is NOT a numeric format. The only way to store a string in a numeric format that is the same for all regional setting is to store it as a Date.
That is, I create a table with a column called DateOfTheEvent (or whatever), and I define its type as a Date (not a String or Integer or anything else)
If I read the date from a Text control for example, I will store as
MyRecord.Fields("DateOfTheEvent").Value = CDate(myText.Text)
in this way, just like you said, the date is stored internally in a regional setting independent way.
To retrive the value:
myText.Text = MyRecord.Fields("DateOfTheEvent").Value
And VB, because it knows the the internal value is stored as Date, will convert automatically the value using the current settings
I have the idea we are saying the same thing just with different words :)
Marco
mstraf at 2007-11-11 17:36:06 >

# 13 Re: Strange date
mstraf,You're confusing yourself.I never said "6/8/06 is NOT a numeric format"!
Besides, the date will be stored in the db in a regional setting[RS] independent way
provided you state the date using the short-date format(& the RS is in the numeric numeric format - m/d/yy or mm/dd/yy or d/m/yy or dd/mm/yy).But if you store the date in the numeric format & the RS is also in the same format(American or English) then your date value will be forced to conform into the American format.For ex.,if you state the date value as 2/12/06(English format;12 is the month) this will be stored as 12/1/06(American format).But if you state the date value as 2/dec/06 & RS is in the numeric setting,the value will be stored as "2/dec/06".
And no we're not saying the same thing.What I am doing is delineating the basic facts on the RS & it's influence(or otherwise) on the way date is stored in the db.
# 14 Re: Strange date
I think we can summize that dates should always be stored as Date in a table, as opposed to strings.
# 15 Re: Strange date
Date values in the numeric & short-date formats are valid dates.The latter is not a string.The latter explicitly states the month & therefore you can instantly understand the date.But the numeric format can cause doubts as to the actual format - American or English.Just look at this date - 1/4/06.Does the 4 mean day or month?
# 16 Re: Strange date
We all agree with you softraj, use Date not integer/string/long or anything else.
# 17 Re: Strange date
We all agree with you softraj, use Date not integer/string/long or anything else.
but that is what I am saying from the beginning, since my first post here!
it is just softray that, from his first post: "it's preferable to store the date in the short-date format". Both Phil and I are trying to argue that using a String means having to convert the format ourself, while using a Date data type there is no need for any conversion at all...
ok sorry, I did not want to create a flame here :)
have a nice weekend everybody :WAVE:
mstraf at 2007-11-11 17:41:10 >

# 18 Re: Strange date
mstraf,I do not think you've understood the gist of the topic we were discussing.More importantly,I do not think you've got the basics right.
In your very 1st posting you've stated "what I've retrieved is 20-09-04 where 20 is day, 09 is month and 04 is year".What you think is a month(9) will not be considered as a month in any Windows platform.And the result "9/4/2020" is also valid - in keeping with the fact that "20-09-04" is not a valid American format.
My request to you is re-read all my postings & test it out in your computer & then you'll know the import of what all I've been stating.
# 19 Re: Strange date
Actually, my first post was this:
http://forums.dev-archive.com/showpost.php?p=457425&postcount=7
:) :) (I admit I am having fun now)
besides, I was the one who proposed a simple solution (just two lines of code) based on Phil's suggestion (that I agree with)
http://forums.dev-archive.com/showpost.php?p=457593&postcount=13
What is your solution? Can you post some code?
Marco
mstraf at 2007-11-11 17:43:12 >

# 20 Re: Strange date
I agree......but I'm not telling with WHOM I agree!
Dates are dates and should be stored as dates. SO THERE! :-
Dates are dates and strings are strings.
Now that I work for a UK software company who has installations all over the world, this is an important thing to remember!
Love and kisses,
L
Laurel at 2007-11-11 17:44:11 >

# 21 Re: Strange date
P.S. softraj:
Phil, marco, and Rich REALLY know their "stuff". I'd listen and learn if I were you! It'll save you a LOT of time programming.
Laurel at 2007-11-11 17:45:16 >

# 22 Re: Strange date
While I'm here, does anyone know the order of wire colors for a straight-through cable? :o)
Laurel at 2007-11-11 17:46:15 >

# 23 Re: Strange date
Hey Gorgeous! How (and where) have you been?
http://www.google.com/search?sourceid=navclient&ie=UTF-8&rls=GGLG,GGLG:2005-33,GGLG:en&q=straight%2Dthrough+cable
mstraf at 2007-11-11 17:47:15 >

# 24 Re: Strange date
Hey Laurel - looks like you've done the opposite to me - USA > UK / UK > USA.
P.S. www.nullmodem.com if a good source for cabling info.
# 25 Re: Strange date
Thanks marco and Rich!
After posting that message, I googled around and found the color order for the straight-through cable. I don't know why I asked you folks for that info. I guess I was being a little lazy.
Where have I been? WELL.......
I got a job with a UK software company (cost control software) and have been doing tech support for them in the US since February. (I'm the only IT-type person on this side of the world for this company!) I'm madly trying to learn SQL Server on my own and not doing a lot of programming now. :o( That's the ONLY thing I don't like about my job. I'm afraid I'm going to lose my programming ability.
Here's where I work: http://www.kildrummy.com
SO....what's new for YOU guys? Rich, who are you working for?
L&K,
Laurel
Laurel at 2007-11-11 17:49:22 >

# 26 Re: Strange date
I've never heard of Kildrummy. Kind of like MRP software I guess...
I'm working for a company in California who provide consultancy services for the landfill industry, and distribute the instruments I used to work with in the UK. http://www.ces-landtec.com/
# 27 Re: Strange date
I formatted the cell in excel to Date. And the date was formatted to dd mmm yy. As simple as that.
Thanks all once again!
shers at 2007-11-11 17:51:17 >
