 |
 |

01-24-2005, 12:03 AM
|
 |
Regular
|
|
Join Date: Jul 2004
Posts: 81
|
|
VB.NET: Extract day, month or year from the Listbox
|
Say i have these dates:
12-2-05......can
12-12-05....can
12-13-05....cannot
12-22-05....cannot
Refer to the above dates, why the below XML tag could not work well with days above "12"... when i send to server..
I could only send 1,2,3,4,5,....up to 12 only.
Code:
"<" & "Date" & " " & "day=" & """" & Convert.ToDateTime(lst.SelectedItem.ToString).Date.Day & """" & " "
& "month=" & """" & Convert.ToDateTime(lst.SelectedItem.ToString).Date.Month & """" & " " & "year=" & """"
& Convert.ToDateTime(lst.SelectedItem.ToString).Date.Year & """" & " >" & _
</" & "Date" & ">" & _
The error message is:
Code:
Additional information: String was not recognized as a valid DateTime.
Does anyone have better solution to solve it....
Thanks
|
|

01-24-2005, 06:55 AM
|
 |
MetaCenturion
Retired Moderator * Guru *
|
|
Join Date: Aug 2001
Location: California, USA
Posts: 16,583
|
|
|
Does it work correctly? As in the .Month returned from all of them is 12?
Maybe it's expecting the date in dd-MM-yy format.
|
|

01-25-2005, 09:51 PM
|
 |
Regular
|
|
Join Date: Jul 2004
Posts: 81
|
|
|
I find the problem is on the Format of the D/MM/YYYY...
After i change the date format, it could work...
Is there any way to format the date so that the program could works well in all
computers without having to worry about whether the computer have set to the
required date format.....
Thanks
|
|

01-26-2005, 08:21 AM
|
 |
MetaCenturion
Retired Moderator * Guru *
|
|
Join Date: Aug 2001
Location: California, USA
Posts: 16,583
|
|
How are the dates getting into the listbox in the first place?
Don't forget that there is also the DateTime.Parse() function that converts a date string into a datetime value.

|
|

01-26-2005, 07:38 PM
|
 |
Regular
|
|
Join Date: Jul 2004
Posts: 81
|
|
Say i have these XML tag
Code:
<book published="New York">
<date day="12" month="1" year="2005" />
</book>
How do i exactly format the date since i am getting three different attributes (day, month and year) from the server......
Say i want the format to be "DD/MM/YYYY"...
I want the format date to be displayed in the listbox...
Does anyone have any idea to combined all three attributes and format instead of format directly the date as a whole....
Thanks
|
|

01-26-2005, 09:00 PM
|
 |
Contributor
|
|
Join Date: Feb 2004
Location: Melbourne, Australia
Posts: 633
|
|
Do you absolutely need the day, etc, separate?
eg:
Code:
<book published="New York">
<date value="12/01/2005"/>
</book>
Then you could just rip it straight out, and parse it into a date variable, using the culture that you want. For example, say you have the date 8th of September, 2005. In british cultures, this would be written 8/9/2005, but in the US, 9/8/2005. If you are given the british version, 8/9/2005, then do this to parse the date correctly, and end up with a date variable in the US culture format:
Code:
Dim sDate As String = "8/9/2005" 'British - 8th Sep 2005
Dim CI As New Globalization.CultureInfo("en-AU")
Dim dd As Date = Date.Parse(sDate, CI)
MessageBox.Show("Day: " & dd.Day & ", Month: " & dd.Month & ", Year: " & dd.Year)
|
Last edited by sgt_pinky; 01-26-2005 at 09:08 PM.
Reason: Fixed error
|

01-26-2005, 10:46 PM
|
 |
Regular
|
|
Join Date: Jul 2004
Posts: 81
|
|
|
yeah...
i need it separate because i get separate dates from the server...
I am not sure how to combine three different attributes and go through the formating of dates...
|
|

01-27-2005, 03:20 PM
|
 |
Contributor
|
|
Join Date: Feb 2004
Location: Melbourne, Australia
Posts: 633
|
|
I'm not really sure what you mean, you will have to explain yourself better.
Code:
Dim sDay as String = "8"
Dim sMonth as String = "10"
Dim sYear as String = "2005"
Dim dDate as Date = Date.Parse(sMonth & "/" & sDay & "/" & sYear)
MessageBox.Show(dDate.ToString("d MMMM yyyy"))
Output is: "8 October 2005"
Is this what you mean?
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|
|
|
 |
|