473,503 Members | 1,769 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

mysql date problem

24 New Member
i am using asp.net......i have a textbox where i am inserting a date in the format 'dd/mm/yyyy' . i have to insert this data into database. but mysql date format is 'yyyy-mm-dd'...how to do that? please help...
May 17 '09 #1
12 3070
prabirchoudhury
162 New Member
hey.. here you go ..

i have done this conversion on C# ,

Expand|Select|Wrap|Line Numbers
  1.  
  2. string str = TextBox1.Text; //put the value you pull from textbox
  3.  
  4.         string[] strArr = str.Split('/');
  5.         string strDD = strArr[0];
  6.  
  7.         string strMM = strArr[1];
  8.         string strYYYY = strArr[2];
  9.  
  10.         string str2 = strYYYY + "-" + strMM + "-" + strDD;
  11.         Message.Text = str2; 
  12.  
  13.  
  14. // str2 is yyyy/mm/dd format 
  15.  
  16.  
  17.  
  18.  
  19.  

you could set up a date picker popup , to pick the date
May 18 '09 #2
r035198x
13,262 MVP
Use the proper API that allows you to pass the values as parameters and therefore will do the conversion automatically for you.
May 18 '09 #3
mikek12004
200 New Member
yes but how can you pass parameter say to the now() function to store date/tome in dd/mm/yy hh:mm:ss and not in the default way mysql does?
May 18 '09 #4
r035198x
13,262 MVP
Don't change the default way that MySQL stores the dates. Just format the dates according to the relevant Locales when you retrieve them for presentation.
May 18 '09 #5
mikek12004
200 New Member
doesn't mysql give you that possibility? in mssql the date function gave me much flexibility regarding that matter (I change from mssql to mysql and I want to make as little changes to the php code as possible)
May 18 '09 #6
r035198x
13,262 MVP
The date function in mssql does not change the way mssql server stores it's dates in the database. It merely changes between varchars and dates.
Like I said, you never need to change the way dates are stored in the database. don't do it and don't look for ways of doing it. People use different date formats on their computers. No need to try and mirror all those formats in the database.
Use the default database date format at the back end and use appropriate API at the front end that does the conversions automatically for you.
May 18 '09 #7
mikek12004
200 New Member
hmmm...maybe I wasn't that clear,I do not care what inner processes mysql do or how its saving date, all I care is that when I draw the date to display it I do not want the american (year-month-day) but the western way (day-month-year) and thought instead of doing it in php after I have drawn the date if there was a way to store it in that format like I did in mssql (I believe it was with the 103 parameter) if on the other hand mysql doesn't give such capabilities...oh well I guess php is the next best way to go
May 18 '09 #8
r035198x
13,262 MVP
Yes, MySQL does have date format functions.
See the mysql refmanual here.
May 18 '09 #9
AmiMitra
24 New Member
thanx for your concern , but please can u help me once more?
when i create the table in mysql where i want to insert that date, should i keep it as varchar or date? because any format i get is in the form .text , which is a string. is there any way to convert string to date?
May 18 '09 #10
AmiMitra
24 New Member
ok i solved it. if i use the convert.datetime function , it again changes the format to dd/mm/yy format. so i need not do that. all i have to do is simply insert the changed format text as string and it is done. it is then inserted as 'yyyy-mm-dd' in the database.am i right?
May 18 '09 #11
r035198x
13,262 MVP
It is inserted in the default format. Once again you shouldn't have to worry about that default format at all. You do have to worry about how you present those dates to users and that is where the Date_Format and Convert_TZ functions come into it.
May 19 '09 #12
prabirchoudhury
162 New Member
make the data Type in mysql as DATE or DATETIME for the Date field

Mysql field type
May 21 '09 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

4
15954
by: Dariusz | last post by:
I am a beginner in PHP and MySQL, and am working through a book and various online tutorials on PHP and MySQL and now stuck - installed everything on "localhost" and it all works fine. My question...
4
4407
by: Neil | last post by:
Hi, I hope this question isn't too far off topic....I'm almost at my wits end trying to figure this out. I have a Mysql database and I wish to automate the backup of the database because I...
5
3715
by: Dominique Javet | last post by:
Hello, I'm new to php and mysql and I use Dreamweaver MX 2004, so sorry for this "newbie" question... I've found no answer in the forum ... I've a date problem with my formular. In my mysql DB...
0
2244
by: Duane Winner | last post by:
Hello all - I'm having a small problem with the mysql startup script that ships with MySQL-3.23.56-1. I'm running on RedHat Linux. It works fine, but I have a backup server that runs a script...
10
2335
by: Newsscanner | last post by:
Hello, In my MySQL database, one of the fields eople have to fill in is "DOB" (Date of Birth). I have now managed to begin inserting data into my DB via a form, the data type for the DOB field...
6
3965
by: Piotr | last post by:
Hi, I have following problem: I use a form in excel to send data into mysql server, everything is ok unless I have to deal with decimals or data fields, this simple are not recognized. For...
0
1697
by: nrip | last post by:
Dear All, I am facing a very peculiar problem. I am reading a CSV file from my JSP code and trying to insert them into MYSQL database. the program first reads a line and then splits it into words...
3
7683
by: Joshepmichel | last post by:
Please to help me to following problem I want to do this 1. create Table Name MEMBER on the Database Name "mytestdb", 2. Add the Values to the Table through the Key board Inputs during running...
6
3925
by: Geoff Cox | last post by:
Hello, at the moment I can add the combined date and time into MySQL using php $dt1 = date("Y-m-d H:i:s"); is it possible to add the date and time separately? I thought it might be
8
3049
by: Tony B | last post by:
I have a string in a existing php script which is in the form "dd/mm/yyyy" and I need to convert it into a suitable format for mysql which is "yyyy-mm-dd" Is there a neat way of doing this in php ?
0
7274
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7453
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5576
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5005
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4670
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3162
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3151
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1507
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
732
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.