DateTime format

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • arunbalait
    New Member
    • Feb 2007
    • 164

    DateTime format

    Hi in my table I have a field for storing date and datetime

    i want to get date from that table using select query...

    for eg select dt from tname....

    Here i want to display only the date not with time.

    And also time alone excluding with date....

    Thanx
  • VijaySofist
    New Member
    • Jun 2007
    • 107

    #2
    Hi ArunBala!

    Convert function can be used for separating date and time from the datetime field. And for your reference use the link given below

    DateTime Format Link
    ------------------------------------
    http://sqljunkies.com/HowTo/6676BEAE-1967-402D-9578-9A1C7FD826E5.sc uk


    Here I have used table name satuserpost, fieldname Ndate

    Query for selecting the date only from a datetime field
    --------------------------------------------------------------------
    select convert(varchar (10),Ndate,105) 'My Date' from satuserpost

    Query for selecting Time from a datetime field
    -----------------------------------------------------------------------
    select convert(varchar (10),Ndate,108) 'My Time' from satuserpost


    All the Best


    With Regards
    Vijay. R

    Comment

    • arunbalait
      New Member
      • Feb 2007
      • 164

      #3
      Hi
      Thanx for your reply

      I have problem with it..
      That is
      select convert(varchar (10),Ndate,105) 'My Date' from satuserpost where ndate='2007-12-15'

      The above query returns no results....

      WIthout where condition it is working. I want to select particular date or time..

      How to do so?



      Originally posted by VijaySofist
      Hi ArunBala!

      Convert function can be used for separating date and time from the datetime field. And for your reference use the link given below

      DateTime Format Link
      ------------------------------------
      http://sqljunkies.com/HowTo/6676BEAE-1967-402D-9578-9A1C7FD826E5.sc uk


      Here I have used table name satuserpost, fieldname Ndate

      Query for selecting the date only from a datetime field
      --------------------------------------------------------------------
      select convert(varchar (10),Ndate,105) 'My Date' from satuserpost

      Query for selecting Time from a datetime field
      -----------------------------------------------------------------------
      select convert(varchar (10),Ndate,108) 'My Time' from satuserpost


      All the Best


      With Regards
      Vijay. R

      Comment

      • Jim Doherty
        Recognized Expert Contributor
        • Aug 2007
        • 897

        #4
        Originally posted by arunbalait
        Hi
        Thanx for your reply

        I have problem with it..
        That is
        select convert(varchar (10),Ndate,105) 'My Date' from satuserpost where ndate='2007-12-15'

        The above query returns no results....

        WIthout where condition it is working. I want to select particular date or time..

        How to do so?
        your posted syntax is verifably correct and should be returning an italian (105) converted date type value as varchar
        What does your data look like in SQL server when you return * from ndate do you have your field set as datetime datatype

        select convert(varchar (10),Ndate,105) [My Date] from satuserpost where Ndate='2007-12-15'

        Jim :)

        Comment

        • arunbalait
          New Member
          • Feb 2007
          • 164

          #5
          Originally posted by Jim Doherty
          your posted syntax is verifably correct and should be returning an italian (105) converted date type value as varchar
          What does your data look like in SQL server when you return * from ndate do you have your field set as datetime datatype

          select convert(varchar (10),Ndate,105) [My Date] from satuserpost where Ndate='2007-12-15'

          Jim :)
          Hi...

          Thanks

          Ya my data format is datetime datatype...

          select convert(varchar (10),Ndate,105) [My Date] from satuserpost where Ndate='2007-12-15'

          the above query gives 0 rows affected...

          Help me plz... I want to take report on particular date... If i have given where condition it doesnt affect any values...


          I want the result for

          select username from mytable where dt='2007-12-18'


          dt= field name in my table.. it is in datetime datatype..

          thanx

          Comment

          Working...