The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Datepicker cant be saved into mysql db
ishan
post Apr 11 2011, 02:31 AM
Post #1


Novice
**

Group: Members
Posts: 26
Joined: 23-November 06
Member No.: 1,070



Hi,

Using jquery datepicker,I have the format of the date returned from Datepicker as (yy-mm-dd) which returns the string as 2011-04-22.

When I want to INSERT it in the MySQL table in the column with datatype as DATE, I get 0000-00-00 saved. Browsing through SO, I found suggestions about FROM_UNIXTIME, but this gives me the date as 1970-01-01.

Any help ?


--------------------
Regards,
iThinksoft - We Know IT
Website : www.ithinksoft.com

OUR SERVICES

Software Development | Web Design & Development | Designs | Online Marketing | Mobile Application Development
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Brian Chandler
post Apr 11 2011, 04:57 AM
Post #2


Jocular coder
********

Group: Members
Posts: 2,212
Joined: 31-August 06
Member No.: 43



Date formats in MySQL are a pain, but you just have to read the documentation. Start with php.net search for function date.

On the other hand, one simple answer is to avoid the MySQL date stuff (apart from anything else, it is interpreted as local time on the server, which for me is in a funny foreign country, which doesn't even have a simple fixed conversion to GMT). Here's a sample table which I found when I checked how I do it:

CODE

// +--------+-------------+------+-----+---------+-------+
// | Field  | Type        | Null | Key | Default | Extra |
// +--------+-------------+------+-----+---------+-------+
// | ocode  | int(4)      |      | PRI | 0       |       | order number
// | src    | varchar(10) | YES  |     | NULL    |       | supplier ('Epoch' etc.)
// | status | varchar(4)  | YES  |     | NULL    |       | open, pend(ing), canc(elled), sent, recd
// | yyyy   | int(4)      | YES  |     | NULL    |       | ) date created
// | mm     | int(2)      | YES  |     | NULL    |       | )
// | avail  | int(8)      |      |     | NULL    |       | expected delivery date
// +--------+-------------+------+-----+---------+-------+    


You still sort by date, using the YYYY, MM, DD fields separately. It also means you can use your own conventions for things like 'vague dates': I have an "expected" value for ordered stock, which can be a date, or things like 'mid-July 2011'. You don't lose much by not using the MySQL date functions.


--------------------
Brian Chandler
Nothing in this post constitutes "commercial solicitation". PayPal does not solicit residents of Japan. Contents may settle in transit. "Legal mind" may or may not be brain-damaged.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 21st April 2014 - 10:14 AM