Sunday, March 11, 2012

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...

ThanxHi 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.scuk

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|||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?

Quote:

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.scuk

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

|||

Quote:

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 :)|||

Quote:

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

No comments:

Post a Comment