rondog Posted June 10, 2008 Share Posted June 10, 2008 I am pulling a date from a mssql table with data type of 'smalldatetime' it looks like this in the database: 6/10/2008, but when I run a fetch array on it and echo it out, it looks like Jun 10 2008. I applied no formatting whatsoever to it. It just comes out looking like that. Any idea why? I am wanting to achieve something that looks like Tuesday, June 10th, 2008 but have had no luck yet. Thanks for any help. Link to comment https://forums.phpfreaks.com/topic/109656-solved-formatting-date/ Share on other sites More sharing options...
DarkWater Posted June 10, 2008 Share Posted June 10, 2008 Make the column datetime and then select the row with DATE_FORMAT(). Link to comment https://forums.phpfreaks.com/topic/109656-solved-formatting-date/#findComment-562627 Share on other sites More sharing options...
rondog Posted June 10, 2008 Author Share Posted June 10, 2008 Make the column datetime and then select the row with DATE_FORMAT(). Will making the column datetime mess with any of the current data in the table? Their is something like 9,000 entries in there at the moment. Link to comment https://forums.phpfreaks.com/topic/109656-solved-formatting-date/#findComment-562631 Share on other sites More sharing options...
DarkWater Posted June 10, 2008 Share Posted June 10, 2008 Make the column datetime and then select the row with DATE_FORMAT(). Will making the column datetime mess with any of the current data in the table? Their is something like 9,000 entries in there at the moment. I strongly doubt it, but make a test table with a smalldatetime, put some entries in and try converting it. =P Link to comment https://forums.phpfreaks.com/topic/109656-solved-formatting-date/#findComment-562639 Share on other sites More sharing options...
rondog Posted June 10, 2008 Author Share Posted June 10, 2008 hehe ok thank you Link to comment https://forums.phpfreaks.com/topic/109656-solved-formatting-date/#findComment-562645 Share on other sites More sharing options...
rondog Posted June 10, 2008 Author Share Posted June 10, 2008 I was about to reply and say PHP was returning an undefined function for date_format..I didnt realized it was a MySQL function. Does the same go for MSSQL because thats what I am using? Any idea on how to write it? This is my current query: <?php include 'mssqlconnect.php'; $date = date("m/d/Y"); $query = mssql_query("SELECT event_date FROM DE_Events WHERE displayOnSite = 'true' AND event_date >= '$date' ORDER BY event_date"); ?> Link to comment https://forums.phpfreaks.com/topic/109656-solved-formatting-date/#findComment-562659 Share on other sites More sharing options...
DarkWater Posted June 10, 2008 Share Posted June 10, 2008 Oh never mind, MSSQL doesn't have a DATE_FORMAT (I don't think so, at least). Honestly, I'd get a MySQL database. Two reasons: 1) Microsoft generally sucks. 2) MySQL has more features, MSSQL doesn't have limit clauses, etc. Link to comment https://forums.phpfreaks.com/topic/109656-solved-formatting-date/#findComment-562661 Share on other sites More sharing options...
rondog Posted June 11, 2008 Author Share Posted June 11, 2008 Trust me I would if I could! Unfortunatly I was dragged into the middle of this project :[ They have a events.cfm page that is using the same table formatting it the way I need to to be so maybe I'll just try and get that file from the client. Thanks anyway! Link to comment https://forums.phpfreaks.com/topic/109656-solved-formatting-date/#findComment-562666 Share on other sites More sharing options...
rondog Posted June 11, 2008 Author Share Posted June 11, 2008 Well I got it fairly quick..Here it is in Cold Fusion: <p> #DateFormat(event_date, "dddd, mmmm dd, yyyy")#<br /> <cfif isDefined("start_hour") and start_hour gt 0> #start_hour#:#start_minute_text# #start_ampm# </cfif> <cfif isDefined("end_hour") and end_hour gt 0> — #end_hour#:#end_minute_text# #end_ampm# </cfif> </p> I dont know cold fusion so I am kind of lost.. I am trying this right now but its not working <?php $query = mssql_query("SELECT DateFormat(event_date, 'dddd, mmmm dd, yyyy') FROM DE_Events WHERE displayOnSite = 'true' AND event_date >= '$date' ORDER BY event_date"); ?> Link to comment https://forums.phpfreaks.com/topic/109656-solved-formatting-date/#findComment-562669 Share on other sites More sharing options...
grimmier Posted June 11, 2008 Share Posted June 11, 2008 try this "SELECT Date_Format(event_date, '%W, %M %D %Y') FROM DE_Events WHERE displayOnSite = 'true' AND event_date >= '$date' ORDER BY event_date" Link to comment https://forums.phpfreaks.com/topic/109656-solved-formatting-date/#findComment-562689 Share on other sites More sharing options...
DarkWater Posted June 11, 2008 Share Posted June 11, 2008 @grimmier: That's MySQL, not MSSQL. =/ Link to comment https://forums.phpfreaks.com/topic/109656-solved-formatting-date/#findComment-562690 Share on other sites More sharing options...
bluejay002 Posted June 11, 2008 Share Posted June 11, 2008 i dont know much bout mssql since am using mysql... so how bout trying to format the date from PHP instead? <?php $date = '6/10/2008'; // you may use the data from the database here instead $formatted_date = date('l, F jS, Y', strtotime($date)); // date format for "Tuesday, June 10th, 2008" echo $formatted_date; // output Tuesday, June 10th, 2008 ?> cheers, Jay Link to comment https://forums.phpfreaks.com/topic/109656-solved-formatting-date/#findComment-562702 Share on other sites More sharing options...
grimmier Posted June 11, 2008 Share Posted June 11, 2008 oops my bad, try this $query = mssql_query("SELECT Format(event_date, 'dddd, mmmm dd, yyyy') FROM DE_Events WHERE displayOnSite = 'true' AND event_date >= '$date' ORDER BY event_date"); Link to comment https://forums.phpfreaks.com/topic/109656-solved-formatting-date/#findComment-562709 Share on other sites More sharing options...
rondog Posted June 11, 2008 Author Share Posted June 11, 2008 i dont know much bout mssql since am using mysql... so how bout trying to format the date from PHP instead? <?php $date = '6/10/2008'; // you may use the data from the database here instead $formatted_date = date('l, F jS, Y', strtotime($date)); // date format for "Tuesday, June 10th, 2008" echo $formatted_date; // output Tuesday, June 10th, 2008 ?> cheers, Jay Hey that worked Jay. Very nice Link to comment https://forums.phpfreaks.com/topic/109656-solved-formatting-date/#findComment-562813 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.