Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 SQL Query Question - FormatDateTime
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

Bookie
Average Member

USA
856 Posts

Posted - 16 October 2003 :  11:33:40  Show Profile  Visit Bookie's Homepage  Send Bookie an AOL message  Send Bookie a Yahoo! Message
Is it possible to use a formatdatetime function on data in a querystring? I'm not talking about the WHERE clause but I'm talking about the fields you're designating to select. More specifically, I have a text field that holds date & time but I need to basically strip away the time and select distince dates. Is this possible? Here's an example of the string I'm trying. I've played with it but I can't get it to work. The field I'm trying to select is called Date_stamp.

strSQL = "SELECT DISTINCT tbljournal.FormatDateTime(Date_stamp, vbshortdate) FROM tblJournal ORDER BY Date_stamp DESC;"


I really don't know if it's possible and, if it is, how I would format it to work correctly. Any help would be appreciated!

Participate in my nonsense

laser
Advanced Member

Australia
3859 Posts

Posted - 16 October 2003 :  14:19:52  Show Profile
FormatDateTime is a VBScript function not a SQL function, so it can't be used the way you are trying to.

I can see what you want to do, but can't think of the syntax to do it
Go to Top of Page

D3mon
Senior Member

United Kingdom
1685 Posts

Posted - 16 October 2003 :  14:32:30  Show Profile  Visit D3mon's Homepage
Use CONVERT, e.g.

strSQL = "SELECT DISTINCT CONVERT(datetime,Date_stamp,101) FROM tblJournal ORDER BY Date_stamp DESC;"

(code 101 will result in mm/dd/yyyy date format (USA), more codes available in SQL Server Books Online)


Snitz 'Speedball' : Site Integration Mod : Friendly Registration Mod
"In war, the victorious strategist only seeks battle after the victory has been won"

Edited by - D3mon on 16 October 2003 14:34:03
Go to Top of Page

redbrad0
Advanced Member

USA
3725 Posts

Posted - 16 October 2003 :  21:08:57  Show Profile  Visit redbrad0's Homepage  Send redbrad0 an AOL message
Some other helpful info would be if you only want to select dates that have a give month, day, or year


DAY
strSql = strSql & " WHERE DATEPART(day, DateField)='" & day(Now) & "'"
MONTH
strSql = strSql & " WHERE DATEPART(month, DateField)='" & month(Now) & "'"
YEAR
strSql = strSql & " WHERE DATEPART(year, DateField)='" & year(Now) & "'"

Brad
Oklahoma City Online Entertainment Guide
Oklahoma Event Tickets
Go to Top of Page

laser
Advanced Member

Australia
3859 Posts

Posted - 16 October 2003 :  21:19:59  Show Profile
Will DatePart work on text fields though ?, from what I've read the second argument to DatePart must be a date expression.
Go to Top of Page

Bookie
Average Member

USA
856 Posts

Posted - 16 October 2003 :  21:41:34  Show Profile  Visit Bookie's Homepage  Send Bookie an AOL message  Send Bookie a Yahoo! Message
quote:
Originally posted by D3mon

Use CONVERT, e.g.

strSQL = "SELECT DISTINCT CONVERT(datetime,Date_stamp,101) FROM tblJournal ORDER BY Date_stamp DESC;"

(code 101 will result in mm/dd/yyyy date format (USA), more codes available in SQL Server Books Online)



I'll give this a shot and let you know how it goes. Thanks!

Participate in my nonsense
Go to Top of Page

redbrad0
Advanced Member

USA
3725 Posts

Posted - 16 October 2003 :  21:45:04  Show Profile  Visit redbrad0's Homepage  Send redbrad0 an AOL message
Yes I am 99% sure it only works on Date fields

Brad
Oklahoma City Online Entertainment Guide
Oklahoma Event Tickets
Go to Top of Page

laser
Advanced Member

Australia
3859 Posts

Posted - 16 October 2003 :  21:57:54  Show Profile
OK, so I would go with the Convert function and not the DatePart function.
Go to Top of Page

Bookie
Average Member

USA
856 Posts

Posted - 16 October 2003 :  22:01:14  Show Profile  Visit Bookie's Homepage  Send Bookie an AOL message  Send Bookie a Yahoo! Message
I'm getting the following error but I'm trying to track it down.

Microsoft JET Database Engine error '80040e14'
Undefined function 'CONVERT' in expression.

Participate in my nonsense
Go to Top of Page

Bookie
Average Member

USA
856 Posts

Posted - 16 October 2003 :  23:10:03  Show Profile  Visit Bookie's Homepage  Send Bookie an AOL message  Send Bookie a Yahoo! Message
Actually, I just thought of something. I'm not using SQL server but an Access database. Would it be any different. By the way, I've been searching and trying stuff but I can't get it to work. I'll keep trying and searching.

Participate in my nonsense
Go to Top of Page

Bookie
Average Member

USA
856 Posts

Posted - 17 October 2003 :  00:57:56  Show Profile  Visit Bookie's Homepage  Send Bookie an AOL message  Send Bookie a Yahoo! Message
Holy cow! That was a pain in the butt!

strSQL = "SELECT DISTINCT CDate(Format([tblJournal].date_stamp,'mm/dd/yyyy')) as date_stamp FROM tblJournal;"[/CODE]

Thanks everyone for pointing me in a direction to figure out the solution which, by the way, was not easy to find. I guess I was looking for the cdate function rather than the convert function. Oh well, it's done now.

Participate in my nonsense
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.32 seconds. Powered By: Snitz Forums 2000 Version 3.4.07