Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Converting Dates to Numerics

Status
Not open for further replies.

programmher

Programmer
May 25, 2000
235
US
How do I convert this SQL stored proc into CF? All the variations I have tried do not work! I need to be able to call this from at least four other CF pages or just call the procedure.

Or, would it just be easier to call the procedure from an embedded CFPROC? If so, what is the proper format? CF continues to error on varchar...

SELECT @MyDate = convert(varchar(8),@MyDateTime,112)
SELECT @MyHour = str(DATEPART(hh,@MyDateTime),2)
if (SUBSTRING(@MyHour,1,1) = ' ' )
BEGIN
SELECT @MyHour = '0' + str(DATEPART(hh,@ThisDateTime),1)
end
SELECT @MyMinute = str(DATEPART(mi,@MyDateTime),2)
if (SUBSTRING(@MyMinute,1,1) = ' ' )
BEGIN
SELECT @MyMinute = '0' + str(DATEPART(mi,@MyDateTime),1)
end
select @Mine = @MyDate + @MyHour + @MyMinute
 
Hey programmher,

It sounds like you're just trying to do some basic time formatting. I think the timeFormat() function will do what you want. Is there a reason this won't work for you?

<cfoutput>#timeFormat(myDateTime,&quot;hh:mm&quot;)#</cfoutput>

Hope this helps,
GJ
 
GunJack,

This doesn't work - CF errors on the formatting. I'm trying to reformat a date like the below example:

07/05/2001 10:30:51 - original format

200107051030 - numeric format

Of course, the dates would vary depending on the input from other pages. I thought I could just do a simple DateTimeFomat and be done with it. Nothing I have tried has worked - not even the example from the keyword search...I don't understand why I can't get a simple format to work!!!

 
Hey programmher,

This should do what you described.

<cfset myDateTime=&quot;07/05/2001 10:30:51&quot;>

<cfoutput>
#dateFormat(myDateTime,&quot;yyyymmdd&quot;)##timeFormat(myDateTime,&quot;hhmm&quot;)#
</cfoutput>

Hope this helps,
GJ
 
GunJack,

Wonderful!! That worked and I also got This to work:

<cfset MyTime = TimeFormat(Now(), &quot;hhmm&quot;)>

<cfset MyDate = DateFormat(Now(), &quot;yyyymmdd&quot;)>

<cfset MyDateTime = ThisDate & ThisTime>

<cfoutput><input type=&quot;text&quot; name=&quot;MyDateTime&quot; value=&quot;#MyDateTime#&quot;></cfoutput>

My last step is to make this accept variables from the page that's calling this - the date will not always be &quot;Now()&quot;.

So far, I am using cfparameters with defaults set at &quot;&quot;. This should do the trick, yes? I am rather hesitant because I do not want to accidentally reset EVERY date already in the database to Now().
 
Hey programmher,

I would do what you said of setting the defaults to blank and then just check before inserting to make sure the dates aren't blank.

GJ
 
Thanks for all your help, GunJack. Cover me - I'm going in!!! (Into the code, that is!)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top