Skip to content

Need a help with datepart function

sa san

Asked Dec 23, 2007, 10:18 PM EST3 answers
Share
LinkedInX

hi,

am having a dropdownlist of months(jan....dec). based on selection i wanted to retrive data from databse, but the field to check for a particular  month is  VDATE in  nvarchar(50). empty dates are inserted as 0, and inserted dates are 1/3/2007. i wanted to retrieve other data. how is it possible to check for a particular months. 

eg: select  details1,details2 from ctable where DATEPART(MONTH,VDATE)=@mnth

invalid cast operation

3 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    Datepart function will work only if variable type is date time
    Change the datatype and try this

    SELECT     stor_id AS EXPR1, ord_num AS EXPR2, ord_date AS EXPR3
    FROM         dbo.sales
    where MONTH( ord_date ) = 3

    Hope this helps :)
    Tracy
    0
  • 0

    if the datatype value is nvarchar(50), then how could i split . the problem with datetime datatype is i cannot entry empty datetime, instead if datetime is not entered am sending 0 ,instead of null.so am storing in string, just given me to split the datetime value.

    thanku 4ur response

    0
  • 0
    try
    {     
       string[] split = strConn.Split(new char[] {'/'});
       string s;
       foreach ( s in split)
       {
         if (s.Trim() != "")
         {
                    
         }
       }        

    MessageBox.Show(Strings.split(1).ToString());
    }
    catch (Exception ex)
    {
    }

    Cheers !!
    Tracy
    0