Go Back  Xtreme Visual Basic Talk > Visual Basic .NET (2002/2003/2005/2008, including Express editions) > .NET General > VB.NET: Extract day, month or year from the Listbox


Reply
 
Thread Tools Display Modes
  #1  
Old 01-24-2005, 12:03 AM
toytoy's Avatar
toytoy toytoy is offline
Regular
 
Join Date: Jul 2004
Posts: 81
Default 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
Reply With Quote
  #2  
Old 01-24-2005, 06:55 AM
Iceplug's Avatar
Iceplug Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: California, USA
Posts: 16,583
Default

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.
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #3  
Old 01-25-2005, 09:51 PM
toytoy's Avatar
toytoy toytoy is offline
Regular
 
Join Date: Jul 2004
Posts: 81
Default

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
Reply With Quote
  #4  
Old 01-26-2005, 08:21 AM
Iceplug's Avatar
Iceplug Iceplug is offline
MetaCenturion

Retired Moderator
* Guru *
 
Join Date: Aug 2001
Location: California, USA
Posts: 16,583
Default

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.
__________________

Iceplug, USN
Quadrill 1 Quadrill 2 (full) Quadrill 3 JumpCross .NET Website is ALIVE! - DL Platform Tour for VB.NET! Posting Guidelines Hint: Specify your location in your user cp profile if you want compassion!
Reply With Quote
  #5  
Old 01-26-2005, 07:38 PM
toytoy's Avatar
toytoy toytoy is offline
Regular
 
Join Date: Jul 2004
Posts: 81
Default

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
Reply With Quote
  #6  
Old 01-26-2005, 09:00 PM
sgt_pinky's Avatar
sgt_pinky sgt_pinky is offline
Contributor
 
Join Date: Feb 2004
Location: Melbourne, Australia
Posts: 633
Default

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
Reply With Quote
  #7  
Old 01-26-2005, 10:46 PM
toytoy's Avatar
toytoy toytoy is offline
Regular
 
Join Date: Jul 2004
Posts: 81
Default

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...
Reply With Quote
  #8  
Old 01-27-2005, 03:20 PM
sgt_pinky's Avatar
sgt_pinky sgt_pinky is offline
Contributor
 
Join Date: Feb 2004
Location: Melbourne, Australia
Posts: 633
Default

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?
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->