PDA

View Full Version : Inserting Dates into Mysql (Euro Format)


kirk
02-11-2009, 06:57 PM
hi everyone,

I want to create a database for our groups library/museum. As I want to eventually put it on the Net I am using DWCS4 and MySql 5.2 with PHP.

Part of the process would be to enter the date of the item (some are very Old) or the date they were donated.

I see that MYSQL uses a different format to the one I am familiar with which is day/month/year.

Can anyone advise how I can use dreamweaver to do this.

I have searched everywhere to get an answer that I understand but I guess I am just thick.

Hope someone can help.

Regards,

Kirk

bee80
02-11-2009, 07:23 PM
you could store the date as a string in mysql if you were entering the dates yourself, create a txt field and then output that txt field with the record set where needed, but if your wanting to search by dates this wouldnt be much use.

davidj
02-11-2009, 09:30 PM
MYSQL has a date field type

you need to swap the date format as MYSQL stores the date as yyyy/m/d

you need to format the date in this fashion

if your using Dreamweaver tools to do this for you then im sorry as its not my bag

if you want to learn how to code then i can help you with this

just let me know

kirk
02-12-2009, 10:10 PM
you could store the date as a string in mysql if you were entering the dates yourself, create a txt field and then output that txt field with the record set where needed, but if your wanting to search by dates this wouldnt be much use.

Thank you bee80 for you reply it is much appreciated.
I have to admit my knowledge of mysql is very limited as you may have guessed. I just want a way to input the date in a euro format because the people in the library/museum are not technology friendly and it would be difficult to get them to input something like year/month/day instead of maybe just 1864. I appreciate the output would also be challenging too but alt least if I could get it input correctly I could look at that again.

Your response is appreciated.

Have a brilliant weekend.

Regards,

Kirk

kirk
02-12-2009, 10:26 PM
MYSQL has a date field type

you need to swap the date format as MYSQL stores the date as yyyy/m/d

you need to format the date in this fashion

if your using Dreamweaver tools to do this for you then im sorry as its not my bag

if you want to learn how to code then i can help you with this

just let me know


HI DavidJ,

Thanks for your reply it is really appreciated.

I know from your tutorial that you are obviously a php Guru and I have looked a some of your tutorials which are great.

I have under instruction adapted some php code in dreamweaver so my experience is quite low.

I am amazed that this date thing is so difficult especially when you think the the mysql date format does not even match the USA never mind the UK.

I can create a database and include a date related table in the database and use DW to submit the form using recordsets if that is any help.

The issue is that the people in the library are even less technology aware than me so it would be very difficult for them to input an item in the museum as year/month/day instead of day/month/year. I would even settle if they could just put the year such as 1864 and MYSQL would be happy.

If there is any guidance for someone such as me then it would be greatly appreciated.

Thank you once again for your reply.

Cheers,

Kirk

davidj
02-12-2009, 11:05 PM
you take the key'd date from the form field

example of key'd date = 10/01/2009

$date = $_POST['datefield'];

you have to perform some malarkey on that field by splitting the values into seperate components

list($d,$m,$y) = explode('/',$date);

now you have the bits you can rearange them


$newdate = "$y/$m/$d";


mysql friendly

edbr
02-13-2009, 12:27 AM
nice code David >snippet bag

kirk
03-18-2009, 12:23 PM
Hi DavidJ,

Thanks for your reply on the date and splitting it to input into mysql database.

As mentioned my php is very poor could you give me an example using a form and inputing the date as described in your previous example.

Eg. a form field date submit button an the input 1/10/2009

Also I have noticed the date range in mysql is quite short starting from the 70,s but we have books that are as old as the 1500's is this still possible or do you think that I should just allow input as a four digit number.

If this is confusing then I apologise.

Thank you very much for your help.

Cheers,

Kirk

davidj
03-18-2009, 11:54 PM
your talking about a unix timestamp

this began in 01/01/1979 and is in seconds from that date

this is not the datatype you are after

you want a date type

Kirk

if you would like to understand PHP better then i can teach you

let me know if it interests you