Go Back   DeveloperBarn Forums > Programming & Scripting > ASP Development

Sponsored Links

Discuss "MS access distinct datetime problem" in the ASP Development forum.

ASP Development - Learn coding practices and tips to get the best out of your Active Server Pages (ASP). The Classic ASP forum is for ASP/VBScript and ASP/JScript applications.


Reply « Previous Thread | Next Thread »
 
LinkBack Thread Tools Display Modes
  #1  
Old July 23rd, 2008, 01:40 AM
Barn Frequenter

 
Join Date: Mar 2008
Posts: 197
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 1
todd2006 is an unknown quantity at this point
Default MS access distinct datetime problem

Hi,

I have a field called order_date which date type is datetime in access

so the data is in this format

08/21/2007 9:30:27 AM
08/21/2007 11:23:32 AM

I only want to display 08/21/2007

can someone tell me what i am doing wrong
Code:
sqltr=  "SELECT Distinct convert(datetime, Order_Date) from Orders order by convert(datetime, Order_Date)"
Code:
sqltr=  "SELECT Distinct (convert(datetime,left(convert(varchar,Order_Date),10),103)) from Orders order by convert(datetime,left(convert(varchar,Order_Date),10),103)"
Code:
sqltr=  "SELECT Distinct (CDate(format(Order_Date,'dd/mm/yyyy'))) from Orders order by CDate(format(Order_Date,'dd/mm/yyyy'))"
Code:
sqltr =  "SELECT Distinct (Order_Date) from Orders order by Order_Date desc"
Code:
sqltr =  "SELECT Distinct (CDate(Order_Date)) from Orders order by CDate(Order_Date) desc"
Code:
sqltr =  "SELECT Distinct (DATE_FORMAT(Order_Date)) from Orders order by DATE_FORMAT(Order_Date) desc"
none of the above query is working
Reply With Quote
Sponsored Links
  #2  
Old July 23rd, 2008, 01:56 AM
Barn Frequenter

 
Join Date: Mar 2008
Posts: 197
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 1
todd2006 is an unknown quantity at this point
Default

this query works

Code:
sqlcoaches =  "SELECT Distinct (Format([Order_Date], 'mm/dd/yyyy')) from Orders order by Format([Order_Date], 'mm/dd/yyyy') desc"

but when dates are displayed they are like this

10/23/1999
11/22/2001
05/2/2008

I want 05/2/2008 at top so the ordering is not working any idea

todd
Reply With Quote
  #3  
Old July 23rd, 2008, 09:35 AM
AOG123's Avatar
Lightning Master

 
Join Date: Mar 2008
Location: Fortress Of Solitude
Posts: 93
Thanks: 6
Thanked 23 Times in 18 Posts
Rep Power: 1
AOG123 is on a distinguished road

Awards Showcase
Microsoft Access 
Total Awards: 1

Default

You want to order by the original format,. this should work as far as i can see,. altough it looks like you've tried something similar

Code:
ORDER BY [Orders].Order_Date DESC;
__________________
If i helped you, make me famous by clicking the

Last edited by AOG123; July 23rd, 2008 at 09:38 AM.
Reply With Quote
  #4  
Old July 23rd, 2008, 10:37 PM
Barn Frequenter

 
Join Date: Mar 2008
Posts: 197
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 1
todd2006 is an unknown quantity at this point
Default

I get this error

[Microsoft][ODBC Microsoft Access Driver] ORDER BY clause ([Orders].Order_Date) conflicts with DISTINCT.

Here is my query

sqltr = "SELECT Distinct (Format([Order_Date], 'mm/dd/yyyy')) from Orders ORDER BY [Orders].Order_Date DESC"

any idea

todd
Reply With Quote
  #5  
Old July 24th, 2008, 10:00 AM
Wolffy's Avatar
Slaprentice of Wolves

 
Join Date: Mar 2008
Location: Peoria, IL
Posts: 175
Thanks: 3
Thanked 24 Times in 21 Posts
Rep Power: 1
Wolffy is on a distinguished road

Awards Showcase
Microsoft .Net 
Total Awards: 1

Default

You may need to use a sub-query then. The following should work:
Code:
Select OrdDate
From (Select Distinct Format(Order_Date, 'mm/dd/yyyy') as OrdDate
         From  Orders)
Order By OrdDate Desc
__________________
Wolffy
------------------------
Opinions expressed are my own and do not necessity reflect those of any sane person. Any code provided is intended to be an example and is provided AS IS. Rework for your specific environment may be required. Void where prohibited by law. Not valid in California. Your mileage may vary.

Last edited by Wolffy; July 24th, 2008 at 10:19 AM.
Reply With Quote
  #6  
Old July 24th, 2008, 10:11 AM
Barn Frequenter

 
Join Date: Mar 2008
Posts: 197
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 1
todd2006 is an unknown quantity at this point
Default

it gives me an error

[Microsoft][ODBC Microsoft Access Driver] Syntax error in FROM clause.

any idea

todd
Reply With Quote
  #7  
Old July 24th, 2008, 10:18 AM
Wolffy's Avatar
Slaprentice of Wolves

 
Join Date: Mar 2008
Location: Peoria, IL
Posts: 175
Thanks: 3
Thanked 24 Times in 21 Posts
Rep Power: 1
Wolffy is on a distinguished road

Awards Showcase
Microsoft .Net 
Total Awards: 1

Default

Looks like I put 1 too many closing parens in there. I modified the post above.
Reply With Quote
  #8  
Old July 24th, 2008, 10:21 AM
Barn Frequenter

 
Join Date: Mar 2008
Posts: 197
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 1
todd2006 is an unknown quantity at this point
Default

tried the query it doesnt do the sorting.

it sorts in asc and the months are not in the right order
Reply With Quote
  #9  
Old July 24th, 2008, 10:24 AM
Wolffy's Avatar
Slaprentice of Wolves

 
Join Date: Mar 2008
Location: Peoria, IL
Posts: 175
Thanks: 3
Thanked 24 Times in 21 Posts
Rep Power: 1
Wolffy is on a distinguished road

Awards Showcase
Microsoft .Net 
Total Awards: 1

Default

Does it appear to be sorted as if the dates are being treated as strings? If so, it may be necessary to convert OrdDate back into the DateTime value for the ORDER BY to work.

[EDIT]Yup. Had to lookup the Format function cause I don't use Access, but it DOES return a string, which will cause the ORDER BY to not work correctly[/EDIT]

Last edited by Wolffy; July 24th, 2008 at 10:27 AM.
Reply With Quote
  #10  
Old July 24th, 2008, 10:28 AM
Barn Frequenter

 
Join Date: Mar 2008
Posts: 197
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 1
todd2006 is an unknown quantity at this point
Default

i tried it like this

Code:
sqlcoaches =  "SELECT Distinct (Format([Order_Date], 'mm/dd/yyyy')) from Orders order BY Format([Order_Date], 'mm/dd/yyyy') DESC"
it still doesnt work
Reply With Quote
Reply

  DeveloperBarn Forums > Programming & Scripting > ASP Development

Bookmarks

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT -4. The time now is 06:46 PM.



Content Relevant URLs by vBSEO 3.2.0