Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Date formatting

Author  Topic 

OldMySQLUser
Constraint Violating Yak Guru

301 Posts

Posted - 2009-01-16 : 05:36:09
How can I return the date field 'ModifiedOn' as a string in the format dd/mm/yyyy for the script:

use Debt
select DebtID,
(select FullName from dbo.Users where UserID = a.OldUserID) OldUserID,
(select FullName from dbo.Users where UserID = a.NewUserID) NewUserID,
(select FullName from dbo.Users where UserID = a.ModifiedBy), ModifiedOn
from DebtAudit a
where ModifiedOn >= '01/13/2009' AND
ModifiedOn < '01/14/2009'

please?

Jai Krishna
Constraint Violating Yak Guru

333 Posts

Posted - 2009-01-16 : 05:37:18
use Debt
select DebtID,
(select FullName from dbo.Users where UserID = a.OldUserID) OldUserID,
(select FullName from dbo.Users where UserID = a.NewUserID) NewUserID,
(select FullName from dbo.Users where UserID = a.ModifiedBy), ModifiedOn
from DebtAudit a
where convert(varchar(11),ModifiedOn,101) >= '01/13/2009' AND
convert(varchar(11),ModifiedOn,101)< '01/14/2009'


Jai Krishna
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-01-16 : 05:39:00
try this
select DebtID,
(select FullName from dbo.Users where UserID = a.OldUserID) OldUserID,
(select FullName from dbo.Users where UserID = a.NewUserID) NewUserID,
(select FullName from dbo.Users where UserID = a.ModifiedBy), ModifiedOn
from DebtAudit a
where dateadd(d,0,datediff(d,0,ModifiedOn)) > dateadd(d,0,datediff(d,0,@date1)) AND dateadd(d,0,datediff(d,0,ModifiedOn)) < dateadd(d,0,datediff(d,0,@date2))
Go to Top of Page

OldMySQLUser
Constraint Violating Yak Guru

301 Posts

Posted - 2009-01-16 : 05:48:40
These solutions are returning the dates as 2009-01-13 09:03:15.610

Where as I need to return the dates like 13/01/2009.
How can I achieve this please?
Go to Top of Page

raky
Aged Yak Warrior

767 Posts

Posted - 2009-01-16 : 05:51:41
use Debt
select DebtID,
(select FullName from dbo.Users where UserID = a.OldUserID) OldUserID,
(select FullName from dbo.Users where UserID = a.NewUserID) NewUserID,
(select FullName from dbo.Users where UserID = a.ModifiedBy),
convert(varchar(11),ModifiedOn,103) as ModifiedOn
from DebtAudit a
where convert(varchar(11),ModifiedOn,101) >= '01/13/2009' AND
convert(varchar(11),ModifiedOn,101)< '01/14/2009'
Go to Top of Page

Nageswar9
Aged Yak Warrior

600 Posts

Posted - 2009-01-16 : 05:53:49
use this,
select DebtID,
(select FullName from dbo.Users where UserID = a.OldUserID) OldUserID,
(select FullName from dbo.Users where UserID = a.NewUserID) NewUserID,
(select FullName from dbo.Users where UserID = a.ModifiedBy), ModifiedOn
from DebtAudit a
where convert(varchar(32),ModifiedOn,103) >= '01/13/2009' AND
convert(varchar(32),ModifiedOn,103)< '01/14/2009'

Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-01-16 : 05:55:07
select DebtID,
(select FullName from dbo.Users where UserID = a.OldUserID) OldUserID,
(select FullName from dbo.Users where UserID = a.NewUserID) NewUserID,
(select FullName from dbo.Users where UserID = a.ModifiedBy), ModifiedOn
from DebtAudit a
where convert(varchar(11),ModifiedOn,103) > '13/01/2009'
AND convert(varchar(11),ModifiedOn,103) < '14/01/2009'
Go to Top of Page

Jai Krishna
Constraint Violating Yak Guru

333 Posts

Posted - 2009-01-16 : 05:56:01
quote:
Originally posted by OldMySQLUser

How can I return the date field 'ModifiedOn' as a string in the format dd/mm/yyyy for the script:

use Debt
select DebtID,
(select FullName from dbo.Users where UserID = a.OldUserID) OldUserID,
(select FullName from dbo.Users where UserID = a.NewUserID) NewUserID,
(select FullName from dbo.Users where UserID = a.ModifiedBy), ModifiedOn
from DebtAudit a
where ModifiedOn >= '01/13/2009' AND
ModifiedOn < '01/14/2009'

please?



select convert(varchar(11),modifiedon,103) from urtable

Jai Krishna
Go to Top of Page

Nageswar9
Aged Yak Warrior

600 Posts

Posted - 2009-01-16 : 05:57:08
U are checking in where condition with another dateformat,please check it once
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-01-16 : 06:00:16
use these links for formatting the date values
check these links for date formats
www.sql-server-helper.com/tips/date-formats.aspx
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=80563
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-01-16 : 07:20:07
If you want to show formatted dates in front end application, do the formation there

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -