jeeva Posted August 29, 2007 Share Posted August 29, 2007 hi frnds, i am having one problem with mysql.Previously i have created one Date field as varchar format.Now i want change that field as date fromat and also the data should be there as date format whatever i have stored previously. i tried to change this but i couldn't get it changed.... can i get this? thanks in advance... jeeva Quote Link to comment https://forums.phpfreaks.com/topic/67183-from-varchar-to-date-format/ Share on other sites More sharing options...
matthewhaworth Posted August 29, 2007 Share Posted August 29, 2007 MySQL forum, not this one. Though you could take all the data out, apply the function strtodate() and enter it all in again. Quote Link to comment https://forums.phpfreaks.com/topic/67183-from-varchar-to-date-format/#findComment-336987 Share on other sites More sharing options...
jitesh Posted August 29, 2007 Share Posted August 29, 2007 <?php echo date("m-d-Y",strtotime("2007-05-10")); ?> Quote Link to comment https://forums.phpfreaks.com/topic/67183-from-varchar-to-date-format/#findComment-337003 Share on other sites More sharing options...
matthewhaworth Posted August 29, 2007 Share Posted August 29, 2007 <?php echo date("m-d-Y",strtotime("2007-05-10")); ?> strtotime() rather, not date.. my error. Quote Link to comment https://forums.phpfreaks.com/topic/67183-from-varchar-to-date-format/#findComment-337006 Share on other sites More sharing options...
jeeva Posted August 29, 2007 Author Share Posted August 29, 2007 many thanks for reply i want to make changes in database itself i mean change the database field as Date format not through code can i make like this? Quote Link to comment https://forums.phpfreaks.com/topic/67183-from-varchar-to-date-format/#findComment-337018 Share on other sites More sharing options...
jitesh Posted August 29, 2007 Share Posted August 29, 2007 table : test1 field : name ALTER TABLE `test1` CHANGE `name` `name` DATE DEFAULT '0000-00-00' NOT NULL Quote Link to comment https://forums.phpfreaks.com/topic/67183-from-varchar-to-date-format/#findComment-337048 Share on other sites More sharing options...
jeeva Posted August 29, 2007 Author Share Posted August 29, 2007 thanks jitesh. but if i do that my previous data will be lost know? Quote Link to comment https://forums.phpfreaks.com/topic/67183-from-varchar-to-date-format/#findComment-337136 Share on other sites More sharing options...
jitesh Posted August 29, 2007 Share Posted August 29, 2007 May be Keep back-up and try. Quote Link to comment https://forums.phpfreaks.com/topic/67183-from-varchar-to-date-format/#findComment-337137 Share on other sites More sharing options...
xyn Posted August 29, 2007 Share Posted August 29, 2007 what was your date format before? what are you changin it to now? Quote Link to comment https://forums.phpfreaks.com/topic/67183-from-varchar-to-date-format/#findComment-337139 Share on other sites More sharing options...
jeeva Posted August 29, 2007 Author Share Posted August 29, 2007 For jitesh: No its not working.... its give the error like "Incorrect date value: '9-4-2007' for column 'ReqDate' at row 1" For Xyn: Previously i have stored data as dd-mm-yyyy with Varchar datatype i want change the field as Date datatype without data lose Quote Link to comment https://forums.phpfreaks.com/topic/67183-from-varchar-to-date-format/#findComment-337153 Share on other sites More sharing options...
jitesh Posted August 29, 2007 Share Posted August 29, 2007 Current data must be in this format Y-m-d "2006-12-01" Otherwise need to flush and re-enter. Quote Link to comment https://forums.phpfreaks.com/topic/67183-from-varchar-to-date-format/#findComment-337165 Share on other sites More sharing options...
jeeva Posted August 29, 2007 Author Share Posted August 29, 2007 ok i will go for re-enter the data. that is the only way i think... many thanks guys....bye.... Quote Link to comment https://forums.phpfreaks.com/topic/67183-from-varchar-to-date-format/#findComment-337167 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.