Date fromat problem
-
hi all i have a label that displaying a date in the format("dd-MM-yyyy"), but my problem is that i want to save it in the format("MM-dd-yyyy"). this what i tried to do: dim dt as DateTime = CType(lblApplicationDate.Text, DateTime) and this is the error i got: String was not recognized as a valid DateTime. what i have to do to solve this issue ??
When you get mad...THINK twice that the only advice Tamimi - Code
-
hi all i have a label that displaying a date in the format("dd-MM-yyyy"), but my problem is that i want to save it in the format("MM-dd-yyyy"). this what i tried to do: dim dt as DateTime = CType(lblApplicationDate.Text, DateTime) and this is the error i got: String was not recognized as a valid DateTime. what i have to do to solve this issue ??
When you get mad...THINK twice that the only advice Tamimi - Code
hi, provide the format in the tostring() function. try this: yourLabel.Text = yourDateTimeObject.ToString("mm/dd/yy")'or ("dd/mm/yy") or whaterver acceptable format. hope this helps
regards :)
-
hi, provide the format in the tostring() function. try this: yourLabel.Text = yourDateTimeObject.ToString("mm/dd/yy")'or ("dd/mm/yy") or whaterver acceptable format. hope this helps
regards :)
thank you .. but i have no problem with displaying format, the problem is how to save the date in different formats. check this
When you get mad...THINK twice that the only advice Tamimi - Code
-
thank you .. but i have no problem with displaying format, the problem is how to save the date in different formats. check this
When you get mad...THINK twice that the only advice Tamimi - Code
where exactly do you want to save it? you could use the various properties like day, month, year ... provided by the datatime object to create a string that you like and save it to ....
regards :)
-
where exactly do you want to save it? you could use the various properties like day, month, year ... provided by the datatime object to create a string that you like and save it to ....
regards :)
1119 wrote:
you could use the various properties like day, month, year
actually this is the way i used to solve it. but i don't think it is the best way to solve the problem thank you
When you get mad...THINK twice that the only advice Tamimi - Code
-
1119 wrote:
you could use the various properties like day, month, year
actually this is the way i used to solve it. but i don't think it is the best way to solve the problem thank you
When you get mad...THINK twice that the only advice Tamimi - Code
Tamimi - Code wrote:
actually this is the way i used to solve it. but i don't think it is the best way to solve the problem
the best way depends upon where you want to store the data. you have not made it clear where you want to save it? i asked you in earlier post. if you are saving the data in a database then you will have to store the datetime object, but if you are storing it in a text file, you can't do that. you will have to format it. for example save the year,month,day... in a file and use it when you want to create a datetime object: datetime dt = new datetime(year,month,day) or you can save the ticks and use it to create the object when you read from the file like: datetime dt = new datetime(ticks) hope this helps.
regards :)
-
hi all i have a label that displaying a date in the format("dd-MM-yyyy"), but my problem is that i want to save it in the format("MM-dd-yyyy"). this what i tried to do: dim dt as DateTime = CType(lblApplicationDate.Text, DateTime) and this is the error i got: String was not recognized as a valid DateTime. what i have to do to solve this issue ??
When you get mad...THINK twice that the only advice Tamimi - Code
Where are you going to save it? If you are saving it to a database, you should not save it as a string, but a date. Use the
DateTime.ParseExact
method to parse the string. You can use any date format that is possible to specify as a format string.--- single minded; short sighted; long gone;
-
hi all i have a label that displaying a date in the format("dd-MM-yyyy"), but my problem is that i want to save it in the format("MM-dd-yyyy"). this what i tried to do: dim dt as DateTime = CType(lblApplicationDate.Text, DateTime) and this is the error i got: String was not recognized as a valid DateTime. what i have to do to solve this issue ??
When you get mad...THINK twice that the only advice Tamimi - Code
If you are going to save the Date in the DB go with Datetime Format. not by String datatype. In case if you have used the datatype as string then you should go with Use the DateTime.ParseExact method to parse the string.
Regards, Satips.:rose:
-
hi all i have a label that displaying a date in the format("dd-MM-yyyy"), but my problem is that i want to save it in the format("MM-dd-yyyy"). this what i tried to do: dim dt as DateTime = CType(lblApplicationDate.Text, DateTime) and this is the error i got: String was not recognized as a valid DateTime. what i have to do to solve this issue ??
When you get mad...THINK twice that the only advice Tamimi - Code
Wy are you getting this from a label? Why not just get the date/time value from the original variable that set the label's date? No conversion and no parsing will be involved then.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
Where are you going to save it? If you are saving it to a database, you should not save it as a string, but a date. Use the
DateTime.ParseExact
method to parse the string. You can use any date format that is possible to specify as a format string.--- single minded; short sighted; long gone;
hi Guffa : simply my question is : if i have a string contains a date (suppose 17/06/2007 format dd/mm/yyyy) how to convert this value to a valid date if my data base has the date format mm/dd/yyyy (or any date format) ?? thank you
When you get mad...THINK twice that the only advice Tamimi - Code
-
hi Guffa : simply my question is : if i have a string contains a date (suppose 17/06/2007 format dd/mm/yyyy) how to convert this value to a valid date if my data base has the date format mm/dd/yyyy (or any date format) ?? thank you
When you get mad...THINK twice that the only advice Tamimi - Code
Tamimi - Code wrote:
if my data base has the date format mm/dd/yyyy
Stop. Database's don't have a format for a date, unless you made the mistake of storing the date as text. Pass the date to a parameter in your SQL insert and you pass this parameter a DateTime value, not a String.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007 -
Tamimi - Code wrote:
if my data base has the date format mm/dd/yyyy
Stop. Database's don't have a format for a date, unless you made the mistake of storing the date as text. Pass the date to a parameter in your SQL insert and you pass this parameter a DateTime value, not a String.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007Dave Kreskowiak wrote:
Stop. Database's don't have a format for a date,
in MS server i could enter a date 06/17/2007. but i could not enter 17/06/2007 . can we consider this a date format problem ??
When you get mad...THINK twice that the only advice Tamimi - Code
-
Dave Kreskowiak wrote:
Stop. Database's don't have a format for a date,
in MS server i could enter a date 06/17/2007. but i could not enter 17/06/2007 . can we consider this a date format problem ??
When you get mad...THINK twice that the only advice Tamimi - Code
Nope. I call it a validation problem. You're not putting the date entered by the user into a DateTime value. You're just taking the string and putting that directly into an SQL statement. That's a really bad idea. If you use a parameterized query, the parameter will format the DateTime value for any SQL Server localization for you. All you have to do is get the text the user entered into a DateTime value, validate it so it's inside a good date range, then pass it to your SQL code.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007