| Author |
Topic |
|
twocans
Starting Member
6 Posts |
Posted - 2008-06-13 : 12:30:52
|
| Hello I am trying to gilter a table by getdate() (i also tried now()) but I cannot seem to be able to do it I place my code below if anyone can help. am grateful, my db is sql 2005. <%Dim Recordset1__MMColParamRecordset1__MMColParam = getdate()If (Request("MM_EmptyValue") <> "") Then Recordset1__MMColParam = Request("MM_EmptyValue")End If%><%Dim Recordset1Dim Recordset1_cmdDim Recordset1_numRowsSet Recordset1_cmd = Server.CreateObject ("ADODB.Command")Recordset1_cmd.ActiveConnection = MM_connpeepeek_STRINGRecordset1_cmd.CommandText = "SELECT usr_image1, dateimage_usr FROM diddle.ps_usr_image WHERE dateimage_usr = ?" Recordset1_cmd.Prepared = trueRecordset1_cmd.Parameters.Append Recordset1_cmd.CreateParameter("param1", 135, 1, -1, Recordset1__MMColParam) ' adDBTimeStampSet Recordset1 = Recordset1_cmd.ExecuteRecordset1_numRows = 0%>if any one can help I would be gratefulk |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-06-13 : 12:40:02
|
| GETDATE() will return timepart also. You need to strip off time part before comparison if you table contains only date value. Use DATEADD(dd,DATEDIFF(d,0,GETDATE()),0) to strip off time part. You dont need parameter. You can directly pass it to querySELECT usr_image1, dateimage_usr FROM diddle.ps_usr_image WHERE dateimage_usr =DATEADD(dd,DATEDIFF(d,0,GETDATE()),0) |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-06-13 : 13:27:48
|
| SELECT usr_image1, dateimage_usr FROM diddle.ps_usr_image WHERE dateimage_usr >=DATEADD(day,DATEDIFF(day,0,GETDATE()),0) and dateimage_usr <DATEADD(day,DATEDIFF(day,0,GETDATE())+1,0)MadhivananFailing to plan is Planning to fail |
 |
|
|
twocans
Starting Member
6 Posts |
Posted - 2008-06-13 : 13:43:46
|
| Thank you gentlemen I have tried what you gave but I get what i was getting earlier.Application uses a value of the wrong type for the current operation. /a.asp, line 19 regardsk |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-06-13 : 13:46:59
|
quote: Originally posted by twocans Thank you gentlemen I have tried what you gave but I get what i was getting earlier.Application uses a value of the wrong type for the current operation. /a.asp, line 19 regardsk
Have you replaced your query with one Madhi provided for the value of Recordset1_cmd.CommandText? |
 |
|
|
twocans
Starting Member
6 Posts |
Posted - 2008-06-13 : 14:09:55
|
| thank youn i tried that too only to get the errorApplication uses a value of the wrong type for the current operation. i have got logmein if u want an invite to my pc hehek |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-06-13 : 14:19:56
|
| http://classicasp.aspfaq.com/date-time-routines-manipulation/could-i-get-a-little-help-with-dates.html |
 |
|
|
twocans
Starting Member
6 Posts |
Posted - 2008-06-14 : 04:46:13
|
| Thank you Visha,I read this "You should try your best to use YYYYMMDD format wherever possible" The date was origanlly entered into my db by using getdate(). when I look at it now in my db column using sqp manager, i see it as mm//dd/yyyy time, I am a little confused, am i only seeing it like that because possibly the tool i use to see it with is reformating the contant for display porpus. Dates are a nightmare thanks for helpk |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-06-14 : 04:50:16
|
quote: Originally posted by twocans Thank you Visha,I read this "You should try your best to use YYYYMMDD format wherever possible" The date was origanlly entered into my db by using getdate(). when I look at it now in my db column using sqp manager, i see it as mm//dd/yyyy time, I am a little confused, am i only seeing it like that because possibly the tool i use to see it with is reformating the contant for display porpus. Dates are a nightmare thanks for helpk
how did it come like mm//dd/yyyy? its not a proper date format.b/w is dateimage_usr a datetime field in your table? |
 |
|
|
twocans
Starting Member
6 Posts |
Posted - 2008-06-14 : 05:39:20
|
| Thank you Visakh16 [dateimage_usr] datetime CONSTRAINT [DF__ps_usr_im__datei__59063A47] DEFAULT getdate() NULL,that is how the date is entered into my database.when i open ems sql manager and see data in my data base I see the date as dd/MM/yyyy, on having a look at the ems controls which i used to help me build my sql db I see under date time format dd/MM/yyyy hh:mm , can you advise me, should i have it so the YYYYMMDD ?? how wuld i have the time. also no matter what db i am using in the future should this be set as my standard.regards and thank youkps i have to pop out and do shopping i will be back in a few hours am grateful for all help. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-06-14 : 10:58:42
|
quote: Originally posted by twocans Thank you Visakh16 [dateimage_usr] datetime CONSTRAINT [DF__ps_usr_im__datei__59063A47] DEFAULT getdate() NULL,that is how the date is entered into my database.when i open ems sql manager and see data in my data base I see the date as dd/MM/yyyy, on having a look at the ems controls which i used to help me build my sql db I see under date time format dd/MM/yyyy hh:mm , can you advise me, should i have it so the YYYYMMDD ?? how wuld i have the time. also no matter what db i am using in the future should this be set as my standard.regards and thank youkps i have to pop out and do shopping i will be back in a few hours am grateful for all help.
SQL Server stores datetime fields in format yyyy-mm-dd hh:mm:ss.xyzGETDATE() function also returns the date in the same format.But if we are storing the date values alone in db the time part will be 00:00:00.000. So for comparison to work correctly we need to strip off time part from GETDATE() value which is done byDATEADD(d,DATEDIFF(d,0,GETDATE()),0) |
 |
|
|
twocans
Starting Member
6 Posts |
Posted - 2008-06-16 : 06:36:15
|
| THank you very much all. This was soo soo helpful.best wishesk |
 |
|
|
|