Aug 8, 2008

Php -date Format & Initial Field Default Value

Free Web Hosting, No Ads > CONTRIBUTE > Computers

free web hosting

Php -date Format & Initial Field Default Value

feipoh
Hello ,

On most tutorial website for mysql all the date format is in this form 2006-10-17..

User table
-----------
User_name VARCHAR(20),
Join_date DATE,
Alive VARCHAR(1),
..etc etc

I was wondering ,

1) is it possible that i can put the date in this format 17/10/2006.. rather the usual 2006-10-17??


Also.... how can i initial a default value to a column..

e.g...
Alive VARCHAR(1) NOT NULL,

When i create a table User

2) How can i initial 'Y' Or 'True/false' as the initial value in column Alive, e.g... if i type

DESCRIBE USER

Field Type NULL Default
it will show-> user_name varchar(20) No
Join_date date No No 00/00/0000
Alive varchar(1) No Y




OR

DESCRIBE USER

Field Type NULL Default
it will show-> user_name varchar(20) No
Join_date date No 00/00/0000
Alive boolean No True



Thank you!

 

 

 


Reply

Galahad
It would have been better, if you had put this into PHP section of the forums... Mods, please move it when you see it...

Here's an example of what you are trying to do:
CODE

CREATE TABLE `probni` (
`field1` VARCHAR(20) DEFAULT 'field test' NOT NULL,
`field2` DATE DEFAULT '00-00-0000' NOT NULL,
`field3` VARCHAR(1) DEFAULT 'Y' NOT NULL
);


As you can see, you should only put DEFAULT keyword, before setting the new default value for the field... Also, I don't think you can change the format of the DATE field, if you're not comfortable with it, use your own format, in a regular text field, or UNIX timestamp in a number field... I think that about covers it...

Oh yes, there is no BOOLEAN type in MySQL (at least in version 4.x), so you can either use ENUM, and specify True and False as it's values (or Yes/No, or others), or use number type, and use 1 and 0...

Hope this helped...

 

 

 


Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Similar Topics

Keywords : php date format initial default

  1. Mysql Changing Date Format - Need a bit of help changi ng the date format in a table (3)



Looking for php, date, format, and, initial, field, default

Searching Video's for php, date, format, and, initial, field, default
advertisement



Php -date Format & Initial Field Default Value



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE