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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Fixing date format on table (sqlite)

Status
Not open for further replies.

Trevoke

Programmer
Jun 6, 2002
1,142
0
0
US
I guess the first question is, will this update each cell with the proper data?

update table set date_cell = (magic involving date_cell)

And if so the next question is..
what's "magic" ? :)

Will I get the proper result with:

Code:
UPDATE mytable
SET date_cell = (SELECT strftime('%Y-%m-%d %H:%M:%S', date_cell); ) ;
?

Or do I need to do something more complicated, like a cursor?

Tao Te Ching Discussions : Chapter 9 (includes links to previous chapters)
What is the nature of conflict?
 
The answer is...
Code:
UPDATE mytable
SET date_cell = (SELECT strftime('%Y-%m-%d %H:%M:%S', date_cell) ) ;

This works.

Tao Te Ching Discussions : Chapter 9 (includes links to previous chapters)
What is the nature of conflict?
 
Trevoke said:
Is there an ANSI compliant answer?

depends

you haven't explained what the "magic" is

it looks like you're setting a date value equal to a reformatted date value of the same date value

in ANSI, that'd be a "no op" -- don't touch it, because it's already a date

:)



r937.com | rudy.ca
Buy my new book Simply SQL from Amazon
 
And in ANSI SQL the SELECT has a FROM-clause.

This is syntactically correct:
UPDATE mytable
SET date_cell = strftime('%Y-%m-%d %H:%M:%S', date_cell);

 
Understood, thanks.
I am indeed reformatting the datetime in that column. I guess there is no ANSI answer then ;-)

Tao Te Ching Discussions : Chapter 9 (includes links to previous chapters)
What is the nature of conflict?
 
well, see, that's just the point -- in ANSI SQL, a DATE is a date is a date

"reformatting" a date in place is meaningless

your date sounds like a VARCHAR

r937.com | rudy.ca
Buy my new book Simply SQL from Amazon
 
It's SQLite, and it was my first database honest-to-$deity implemented from scratch. I told it to be a datetime. I think it was a varchar anyway.
But now it's OK. I'm in Mysql. It's definitely a datetime. (I had issues doing the data transfer because some of the values in sqlite had microseconds tacked on).

Tao Te Ching Discussions : Chapter 9 (includes links to previous chapters)
What is the nature of conflict?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top