473,657 Members | 2,765 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 3084
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

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

Similar topics

4
15964
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 is as follows. I have a guestbook type code I'm trying to write, but when the results get printed to a webpage, it outputs completely nothing as what was entered in the guestbook database. No errors appear to be generated, and I can't see if...
4
4418
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 don't wish to rely on the web host doing so. I am using the "dbsender.php" script, which is written for this exact purpose (available at hotscripts.com). If I execute the script via my browser, the database is emailed to me in a 'gzip' format, which...
5
3722
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 my filed "date" in table "experience" is like this: Y-m-d (2002-07-23). My fied`date` is date, NOT NULL with no default entry My form read well the date data depending the id, (pe. 30.02.2003), but when I submit a new date, I receive as result...
0
2269
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 that passes these commands remotely through ssh: (1) ssh dbsys-dc "sudo /etc/init.d/mysql stop" (2) ssh dbsys-dc "sudo tar
10
2360
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 is "DATE", but every time I add data and then check my db, I see the DOB displayed as "0000-00-00". Has anyone got any idea how I could put this right? TIA,
6
3976
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 example In excel in mySQL 45,45 -> 45 2005-01-01 -> 0000-00-00
0
1704
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 using the split function and then inserts them into different fields of the database. But the problem is that the JSP ; token=line.split(" "); DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
3
7696
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 the My Java Application.; Therefore I used this following codes, It Consists the seperate parts for the Raede and Member Class for the purposely I craetes. 3. I have problem to Parsing the values to SQL statement, that Consists on the Run Time...
6
3933
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
3054
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
8302
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8820
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
7314
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6162
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5630
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4150
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2726
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 we have to send another system
2
1937
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1601
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.