Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update dates in table 2

Status
Not open for further replies.

aspx

Programmer
Jul 25, 2002
52
BG
Hi!
I want to create stored procedure which updates field of datetime-type in order to change format from 'dd/mm/yyyy' to 'mm/dd/yyyy' (Errors will not occur - I'm sure)...
Something like:
Update table Mytable
Set Date1=(mm/dd/yyyy)
Where Date1=(dd/mm/yyyy)...

Is it possible?

Thanx in advance!!
 
You dont actually need to update the dates. Dates are stored as numerical values and can be displayed in a number of formats, see books on line (cast and convert)

use something like

select (datetime, yourdatefield, 101)

101 code, = mm/dd/yyyy

Andy
 

You should use Convert() funcion when you use Select statement to show these dates anywhere on your forms or reports.

Like this ;
Select Convert(varchar(10) , Date1 , 103) from table
for mm/dd/yyyy


Select Convert(varchar(10) , Date1 , 101) from table
for dd/mm/yyyy

I think it is no matter that how dates are saved in the database.

Muhammad Essa Mughal
Software Engineer
essamughal@yahoo.com
 

Ho , Sorry I made a mistake here in my previous post , correct is ,

Select Convert(varchar(10) , Date1 , 101) from table
for mm/dd/yyyy

Select Convert(varchar(10) , Date1 , 103) from table
for dd/mm/yyyy



Muhammad Essa Mughal
Software Engineer
essamughal@yahoo.com
 
But, anyway, How to create Update-query?
 
I take it the date that is handed to your procedure is a string? In that case, you just use the convert function
to convert it to a date and enter the proper format in the convert.

Kris Simonis
Topdesk Information Systems
 
LPopov,

What do you intend to do with an update statemtn? If you want to change the format, it cna't be done as has been mentioned. Datetime coulmns are essentially number fields. If you store the date in the format mm/dd/yyyy it will be stored just the same as if you store mmm dd yyyy, yyyy-mm-dd, etc.

If you are soring dates as character columns and want to change the format, you can write an update statement using string and/or convert functions. Let us know the data tyep, the conversion required and why.

By the way, I recommend storing dates and times in datetime datatype columns. using character columns to stores dates can cauase multiple problems.

Chek out the following link.

Handling Dates in SQL Server
Terry L. Broadbent - DBA
Computing Links:
faq183-874 contains "Suggestions for Getting Quick and Appropriate Answers" to your questions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top