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 2000 Forums
 SQL Server Development (2000)
 Convert Date to MM/DD/YY

Author  Topic 

Dorffius
Starting Member

36 Posts

Posted - 2002-01-29 : 13:20:47
I have a query running but I need the current date to be inserted into it in this form:

SELECT * FROM TABLE WHERE Date='???? Current date in this format-MM/DD/YY????'

This matches up with the fields in the table. Anyone got some code for that or links?

Thanks for the help.

nr
SQLTeam MVY

12543 Posts

Posted - 2002-01-29 : 13:24:08
SELECT * FROM TABLE WHERE Date=covert(datetime,'mm/dd/yy',1)

look at the convert styles.



==========================================
Cursors are useful if you don't know sql.
Beer is not cold and it isn't fizzy.
Go to Top of Page

Dorffius
Starting Member

36 Posts

Posted - 2002-01-29 : 13:41:59
K, I've tried that and it still doesn't work.

I've tried...

(convert(datetime,'mm/dd/yy',1))
'convert(datetime,'mm/dd/yy',1)'
"convert(datetime,'mm/dd/yy',1)"
("convert(datetime,'mm/dd/yy',1)")
('convert(datetime,'mm/dd/yy',1)')

and none of them work. Thanks anyways for the help though.

Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2002-01-29 : 13:53:26
the 'mm/dd/yy' is meant to be your date string variable in that format.

e.g.
SELECT * FROM TABLE WHERE Date=convert(datetime,'01/29/00',1)



==========================================
Cursors are useful if you don't know sql.
Beer is not cold and it isn't fizzy.

Edited by - nr on 01/29/2002 13:53:57
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2002-01-29 : 13:56:22
or did you want everything for todays date and you have the date in the database in the format 'mm/dd/yy' (not a good idea).

SELECT * FROM TABLE WHERE Date=convert(varchar(8),getdate(),1)



==========================================
Cursors are useful if you don't know sql.
Beer is not cold and it isn't fizzy.
Go to Top of Page

Dorffius
Starting Member

36 Posts

Posted - 2002-01-29 : 14:10:52
That worked perfectly, thanks for the help.

BTW, why is that date format in the database not a good idea?

Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2002-01-29 : 15:29:31
It's never a good idea to use mm/dd/yy or dd/mm/yy as it is ambiguous.
Sooner or later someone will get the date format wrong and you will hopefully get an error - worse is that you may not get an error until the 13th of the month, just wrong data before that.
Better to use yyyymmdd for data transfer and datetime fields in the database.
dd mmm yyyy is ok too if you will never use different languages.

==========================================
Cursors are useful if you don't know sql.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -