jasocke2
asked on
Inserted date "dd/mm/yyyy" but when I view it it comes up "mm/dd/yyyy"
Hi,
I have recently Inserted a Gig of a band into a database and I have a pop-up calender where the date comes from, when I click on the date I want it inserts it in to the box beside it...
for example if i selected 8th May, in the box it would put in 08/05/2006, when I submit the querey, it goes into the database fine, but when I "View all gigs" the Gig comes up as 05/08/2006.
Is it somthing to do with the insert statement?
INSERT INTO GIG(Gig_Day,Gig_Date,Venue ,Other_ban ds,Additio nal_Info,E mail_us)
VALUES('#FORM.Gig_Day#','# FORM.Gig_D ate#','#FO RM.Venue#' ,'#FORM.Ot her_bands# ','#FORM.A dditional_ Info#','#F ORM.Email_ us#')
does the "Gig_date" need to be formatted somehow?
thanks
I have recently Inserted a Gig of a band into a database and I have a pop-up calender where the date comes from, when I click on the date I want it inserts it in to the box beside it...
for example if i selected 8th May, in the box it would put in 08/05/2006, when I submit the querey, it goes into the database fine, but when I "View all gigs" the Gig comes up as 05/08/2006.
Is it somthing to do with the insert statement?
INSERT INTO GIG(Gig_Day,Gig_Date,Venue
VALUES('#FORM.Gig_Day#','#
does the "Gig_date" need to be formatted somehow?
thanks
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
you may have to treat the date as a list and pull each value out into the createDate function.
myDate = createDate(listgetat(form. calendar,3 ,'/'),list getat(form .calendar, 2,'/'),lis tgetat(for m.calendar ,1,'/'))
This will create a date object and notice that createDate goes( year,month,day) using list get at will pull those values.
values('#myDate#')
I agree that having this field set to a string is a problem and you should probably, if possible, add a new column called Gig_Date_Dateformat and update that column with actual dates. Allowing you to keep the old column.
myDate = createDate(listgetat(form.
This will create a date object and notice that createDate goes( year,month,day) using list get at will pull those values.
values('#myDate#')
I agree that having this field set to a string is a problem and you should probably, if possible, add a new column called Gig_Date_Dateformat and update that column with actual dates. Allowing you to keep the old column.
ASKER
Thanks!!
Which bit of code would I need to put that into and how would I go about doing it?
Many thanks
Which bit of code would I need to put that into and how would I go about doing it?
Many thanks
The date being changed to data type date shouldn't affect other things any more than just doing a search for whereever you may insert or update this column and then changing the code slightly - it's just a matter of removing the ' around it.
I'm always amazed at the number of people who don't use a date field for date cause of "problems" when in reality you're setting yourself up for "problems" when you don't.
Now here is the clincher - let the db do whatever it wants with the formatting - as long as you know how to inerpret it.
Use jtreher's approach to the date list then use my #dateformat(Gig_Date,"d/mm /yyyy")# to display the date.
If the date is inserted to db - you can view the date in anyformat you want.
I'm always amazed at the number of people who don't use a date field for date cause of "problems" when in reality you're setting yourself up for "problems" when you don't.
Now here is the clincher - let the db do whatever it wants with the formatting - as long as you know how to inerpret it.
Use jtreher's approach to the date list then use my #dateformat(Gig_Date,"d/mm
If the date is inserted to db - you can view the date in anyformat you want.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
this will always work
1. because you fixed the location to us so coldfusion don't need to guess.
2. us format is always MM/DD/YYYY.
as cf server will swap the month and date if it become a valid date after swap.
good luck
1. because you fixed the location to us so coldfusion don't need to guess.
2. us format is always MM/DD/YYYY.
as cf server will swap the month and date if it become a valid date after swap.
good luck
ASKER
Thanks all of you, sorry for been stupid but where does it go again?
<CFIF Session.LoggedIn NEQ "True">
<CFLOCATION URL="/students/jasocke2/gi gadded.cfm ">
</CFIF>
(here??)-----myDate = createDate(listgetat(form. gig_date,3 ,'/'),list getat(form .gig_date, 2,'/'),lis tgetat(for m.gig_date ,1,'/'))
<cfquery datasource="jasvasquez-acc ess">
INSERT INTO GIG(Gig_Day,Gig_Date,Venue ,Other_ban ds,Additio nal_Info,E mail_us)
VALUES('#myDate#',#createo dbcdate(fo rm.Gig_Dat e)#,'#FORM .Venue#',' #FORM.Othe r_bands#', '#FORM.Add itional_In fo#','#FOR M.Email_us #')
</cfquery>
<CFIF Session.LoggedIn NEQ "True">
<CFLOCATION URL="/students/jasocke2/gi
</CFIF>
(here??)-----myDate = createDate(listgetat(form.
<cfquery datasource="jasvasquez-acc
INSERT INTO GIG(Gig_Day,Gig_Date,Venue
VALUES('#myDate#',#createo
</cfquery>
yes that's right
just put it anywhere before your cfquery will do
ASKER
its saying... Variable MYDATE is undefined.
thanks
thanks
<cfset MYDATE = "#ListGetAt(form.Gig_Date, 2,"/")#/#L istGetAt(f orm.Gig_Da te,1,"/")# /#ListGetA t(form.Gig _Date,3,"/ ")#">
ASKER
if I select say the 19th May (19/05/2006) and insert it like that, it goes in fine, if the number in the month column is 12 or less then it inserts it mm/dd/yyyy but if its above 12 it inserts it dd/mm/yyyy which is how I want to be inserted into the database.
I did a test and inserted 09/05/2006 and when I looked in the database it stored it as 05/09/2006..
thanks