.NET Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgramming.NET Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old February 11th, 2003, 12:13 AM
joephoenix joephoenix is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Posts: 26 joephoenix User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Pulling parts of a date from a SQL table

I've got two date fields in a SQL table, dateStarted and dateEnded. I'm trying to pull the day, month and year info from them into separate textboxes (i.e. txtMth, txtDay, txtYear, txtMth2, txtDay2, txtYear2) using VB. Assuming I've already open the SQL connection how would I proceed to populate the textboxes w/ the days, months, and years separately?

Reply With Quote
  #2  
Old February 11th, 2003, 12:29 AM
Andrew Andrew is offline
dotNetBB Forums Developer
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Posts: 265 Andrew User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to Andrew Send a message via AIM to Andrew Send a message via Yahoo to Andrew
Are you trying to do the date parts in ASP, ASP.NET or SQL? It's slightly different for each way of creating it.<br><br>Classic ASP (assumes we are assigning the date value to the variable) <div class="msgQuoteWrap"><div class="msgCode"><br><%<br>Dim dateStarted <br>dateStarted = {assign value from SQL recordset}<br>Dim dsMonth : dsMonth = Month(dateStarted)<br>Dim dsDay : dsDay = Day(dateStarted)<br>Dim dsYear : dsYear = Year(dateStarted)<br>%></div></div><br><br>ASP.NET (using VB.NET)<div class="msgQuoteWrap"><div class="msgCode"><br>Dim dateStarted As Datetime = {assign value from SQL Recordset}<br>Dim dsMonth as String = dateStarted.ToString("mm")<br>Dim dsDay as String = dateStarted.ToString("dd")<br>Dim dsYear as String = dateStarted.ToString("yyyy")<br></div></div><br><br>SQL (use this to output individual values, assumes value of dateStarted) <div class="msgQuoteWrap"><div class="msgCode"><br>DatePart(mm, dateStarted) -- month<br>DatePart(dd, dateStarted) -- day<br>DatePart(yyyy, dateStarted) -- year<br></div></div><p> </p><p><hr size="1" width="50%" align="left" />dotNetBB Forum Developer<br><b><i>Building A Better Community, One Post At A Time</i></b><br><a href="http://www.dotnetbb.com" target="_blank">www.dotnetbb.com</a></p>

Reply With Quote
  #3  
Old February 11th, 2003, 01:32 AM
joephoenix joephoenix is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Posts: 26 joephoenix User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
ASP.NET as always. So for that example, would the name of the SQL field go in where {assign value from SQL Recordset} is? Am I understanding that right?

Reply With Quote
  #4  
Old February 11th, 2003, 01:34 AM
Andrew Andrew is offline
dotNetBB Forums Developer
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Posts: 265 Andrew User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to Andrew Send a message via AIM to Andrew Send a message via Yahoo to Andrew
Yes, my fault, I should have said DataReader (or whatever method you are using) since Recordsets no longer exist in .NET.<p> </p><p><hr size="1" width="50%" align="left" />dotNetBB Forum Developer<br><b><i>Building A Better Community, One Post At A Time</i></b><br><a href="http://www.dotnetbb.com" target="_blank">www.dotnetbb.com</a></p>

Reply With Quote
  #5  
Old February 11th, 2003, 02:09 AM
joephoenix joephoenix is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Posts: 26 joephoenix User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
So I could do the first variable like so:<br><br><div class="msgQuoteWrap"><div class="msgCode">Dim dateStarted As Datetime = Trim(objSQLListPick.returnDataViewValue(intCounter )("dateInTable").ToString())</div></div> <br><br><img src="/forum/emoticons/idea.gif" alt="idea">

Reply With Quote
  #6  
Old February 11th, 2003, 02:13 AM
Andrew Andrew is offline
dotNetBB Forums Developer
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Posts: 265 Andrew User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to Andrew Send a message via AIM to Andrew Send a message via Yahoo to Andrew
You would need to do...<br><br>Dim dateStarted As String = Trim(objSQLListPick.returnDataViewValue(intCounter )("dateInTable").ToString())<br><br>Since you are using a .ToString() on the end. Otherwise you could use the Datetime as you previously defined.<p> </p><p><hr size="1" width="50%" align="left" />dotNetBB Forum Developer<br><b><i>Building A Better Community, One Post At A Time</i></b><br><a href="http://www.dotnetbb.com" target="_blank">www.dotnetbb.com</a></p>

Reply With Quote
  #7  
Old February 11th, 2003, 09:40 PM
joephoenix joephoenix is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Posts: 26 joephoenix User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Well, it works both ways apparently. Thanks for your help.

Reply With Quote
  #8  
Old February 11th, 2003, 09:47 PM
Andrew Andrew is offline
dotNetBB Forums Developer
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Posts: 265 Andrew User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to Andrew Send a message via AIM to Andrew Send a message via Yahoo to Andrew
<img src="/forum/emoticons/yeah.gif" alt="yeah"><p> </p><p><hr size="1" width="50%" align="left" />dotNetBB Forum Developer<br><b><i>Building A Better Community, One Post At A Time</i></b><br><a href="http://www.dotnetbb.com" target="_blank">www.dotnetbb.com</a></p>

Reply With Quote
  #9  
Old February 11th, 2003, 11:30 PM
joephoenix joephoenix is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Posts: 26 joephoenix User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Cute. <br><br>One thing I noticed; I just realized I need to convert the month value from numeric to alpha and vice-versa (ex: 2 to February and back). How can this be accomplished?

Reply With Quote
Reply

Viewing: ASP Free ForumsProgramming.NET Development > Pulling parts of a date from a SQL table


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT