|
-
Apr 2nd, 2000, 09:47 PM
#1
Thread Starter
New Member
HI
When i use this code:
xyz=format(text1.text, "dd.mm.yyyy")
and i type in text1 for example "12.03.2000" VB5.0 changes the date to something else. can someone explain me why this happen? i just want to get sure that the date format is dd.mm.yyyy
alex
-
Apr 2nd, 2000, 10:02 PM
#2
Frenzied Member
it could be something to do with the fact that 12.03.2000 could mean the 12th of March or the 3rd of december, vbwill usually interpret this as the 3rd of december for some strange reason. Unfortunatly I can't remember the trick to get around this
-
Apr 2nd, 2000, 10:06 PM
#3
Addicted Member
I'm sorry Alex W, but you'll have to elaborate a little more on your code before I spot your exact problem.
I'll give it a shot though. First of all, "dd.mm.yyyy" is not a valid date format, so you won't really be able to use it anywhere else. What data type is your variable "xyz"? Is it a Date type or a String type? If you declared xyz as a Date then it will store any date passed to it in your system's default format (as defined in the Control Panel). However, if you store it in a String you will obviously have whatever you put in it. Oh and something else, you cannot usually format the text into a date format you must first use a function that will convert the text in to a Date format, such as DateValue. So after saying all that you could try the folling:
Dim xyz As String
xyz = Format(DateValue(text1.Text), "dd.mm.yyyy")
Hope this helps. If not I'll be happy to help some more if you need it.
-
Apr 4th, 2000, 07:14 AM
#4
Fanatic Member
I guess that you want to make sure you get DD/MM and the year bit is always at the end, and what you dont want is MM/DD and the year bit...same place
If thats correct, then maybe you can just switch the day and month over?
maybe something like:
dim thedate$ as string *10
dim newdate$ as string *10
dim tday as integer
dim tmonth as integer
dim tyear as integer
thedate$=left$(date$,10)
tyear = right$(thedate$,4)
tmonth=left$(thedate$,2)
tday=mid$(thedate$,4,2)
newdate$=format$(theday,"00") & ":" & format$(themonth,"00") & ":" & format$(tyear,"0000")
i hope that helps and sorry tht its not documented, but just check out each of the keywords in VB help
DocZaf
{;->
-
Apr 4th, 2000, 07:58 AM
#5
Hyperactive Member
FYI
The DateValue function (and all conversion or reading of dates by VB) is done using the System format as a guideline.
This means that if your machine is set to display dates as "MM/DD/YYYY" then it will always assume that you are giving it the month first... then the day... then the year.
*IF* however you give it something like 14/02/2000 then it realises that you have broken its original format and will simply consider you to have switched it in which case it will then assume the format is "DD/MM/YYYY" for that instance only.
This works very well as it follows exactly the same way most other windows applications treat dates because it assumes you wouldn't have told your system to display dates in that way unless you were also going to enter them in that way.
Hope it helps
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|