Notices
Computer & Technology Related Post here for help and discussion of computing and related technology. Internet, TVs, phones, consoles, computers, tablets and any other gadgets.

MySQL date format

Thread Tools
 
Search this Thread
 
Old 19 June 2003, 06:38 PM
  #1  
Dream Weaver
Scooby Regular
Thread Starter
 
Dream Weaver's Avatar
 
Join Date: Feb 2000
Location: Lancashire
Posts: 9,844
Received 0 Likes on 0 Posts
Question

Anyone know if you can store the date in MySQL in the "normal" format?

Currently it stores dates as YYYY-MM-DD, which is odd, and a particular pain when using the ASP date function.

Anyone any ideas, other than creating a function to read or store the standard format?
Old 19 June 2003, 08:09 PM
  #2  
Andrewza
Scooby Regular
 
Andrewza's Avatar
 
Join Date: Jan 2002
Posts: 667
Likes: 0
Received 0 Likes on 0 Posts
Post

Nope, I use MySQL with PHP and have functions to go from mysql date to unixtime and back. IIRC doesn't ASP use an even more annoying US format anyhow? (Hence various date bugs on this BBS )
Old 19 June 2003, 11:07 PM
  #3  
Dream Weaver
Scooby Regular
Thread Starter
 
Dream Weaver's Avatar
 
Join Date: Feb 2000
Location: Lancashire
Posts: 9,844
Received 0 Likes on 0 Posts
Post

Never noticed any probs before Andy, just use date, or day(month), or now and it gives you the whole shebang

Looks like I need to write a function for it then.
Old 20 June 2003, 08:31 AM
  #4  
AdrianFRST
Scooby Regular
 
AdrianFRST's Avatar
 
Join Date: Oct 2000
Posts: 368
Likes: 0
Received 0 Likes on 0 Posts
Post

function getdate(epoch)
'converts unix epoch date to UK date / time format...
getdate = dateadd("s", epoch, #1970-01-01#)
end function



Dates in ASP depend on server locale. I've not had any problems with them, but then again I use either my own servers or Titan's, which are correctly set up for the UK.
Old 20 June 2003, 09:02 AM
  #5  
Dream Weaver
Scooby Regular
Thread Starter
 
Dream Weaver's Avatar
 
Join Date: Feb 2000
Location: Lancashire
Posts: 9,844
Received 0 Likes on 0 Posts
Post

Thats why I have also never had any probs then, all hosted with Titan

Cheers Ady, where to use it then? Presume that will read the date format from the db, then change it for displaying. I will also need an input function for adding the date as well.
Old 20 June 2003, 10:21 AM
  #6  
Andrewza
Scooby Regular
 
Andrewza's Avatar
 
Join Date: Jan 2002
Posts: 667
Likes: 0
Received 0 Likes on 0 Posts
Post

if you're just inserting things as created into mysql you just do

insert into table (date) values(NOW()), which will give you now, however you've almost definitely got to edit the dates I suspect which means creating a function to do it unfortunately.

If you were using PHP:
Code:
/*
	Calculate unixtime from a MySQL DATETIME
*/

function unixtime_from_mysql($mysql_date) {

	if($mysql_date) {
		list( $date, $time ) = split( " " , $mysql_date );
		list( $year, $month, $day ) = split( "-" , $date );
		list( $hour, $minute, $second ) = split( ":" , $time);
		$unixtime = mktime( $hour , $minute , $second , $month , $day , $year );
		return $unixtime;
	} else {
		return 0;
	}

}

/*
	Calculate a MySQL format date from unixtime
*/

function mysql_from_unixtime($unixtime) {
	if($unixtime) {
		return date("Y-m-d H:i:s",$unixtime);
	} else {
		return "0000-00-00 00:00:00";
	} 

}
Old 20 June 2003, 07:20 PM
  #7  
David_Wallis
Scooby Regular
 
David_Wallis's Avatar
 
Join Date: Nov 2001
Location: Leeds - It was 562.4bhp@28psi on Optimax, How much closer to 600 with race fuel and a bigger turbo?
Posts: 15,239
Likes: 0
Received 1 Like on 1 Post
Post

how about simply...

temp = "2003-06-20"

mysqldate = Right(Date,4) & "-" & Mid(Date, 4,2) & "-" & Mid(Date, 7,2)
Wscript.echo mysqldate



AspDateFromDb = Right(temp,2) & "/" & Mid(Temp, 6,2) & "/" & Left(Temp ,4)
wscript.echo AspDateFromDb
Old 21 June 2003, 04:27 PM
  #8  
legacyPete
Scooby Regular
 
legacyPete's Avatar
 
Join Date: Dec 2001
Posts: 202
Likes: 0
Received 0 Likes on 0 Posts
Post

Why not format it using MySQL?

select DATE_FORMAT(field, '%d/%m/%Y') AS myDate from table
Old 26 June 2003, 02:37 PM
  #9  
Dream Weaver
Scooby Regular
Thread Starter
 
Dream Weaver's Avatar
 
Join Date: Feb 2000
Location: Lancashire
Posts: 9,844
Received 0 Likes on 0 Posts
Post

strDate = year(now) & "/" & month(now) & "/" & day(now)

Seems to do the trick.
Old 26 June 2003, 02:43 PM
  #10  
David_Wallis
Scooby Regular
 
David_Wallis's Avatar
 
Join Date: Nov 2001
Location: Leeds - It was 562.4bhp@28psi on Optimax, How much closer to 600 with race fuel and a bigger turbo?
Posts: 15,239
Likes: 0
Received 1 Like on 1 Post
Post

cool.. I was the closest then
Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
JimBowen
ICE
5
02 July 2023 01:54 PM
Frizzle-Dee
Essex Subaru Owners Club
13
09 March 2019 07:35 PM
yabbadoo4
ScoobyNet General
11
30 September 2015 10:33 PM
Littleted
Computer & Technology Related
0
25 September 2015 08:44 AM
farmerwrx
Computer & Technology Related
14
10 September 2015 11:59 AM



Quick Reply: MySQL date format



All times are GMT +1. The time now is 01:40 AM.