• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Date Time insert problem

New Here ,
Nov 27, 2006 Nov 27, 2006

Copy link to clipboard

Copied

Heeeeelp please!
Dates. And Times. Raise your hand if you hate them.
I have a problem with dates/times and I was hoping that someone can help.
I am developing a vacancy list.
On the list vacancies page, I want to display all vacancies that closingDate >= #now()#
On the add a vacancy I am asking the user to insert a date (closingDate) for a vacancy. However, when I insert the date, it defaults to different result depending on the function I use. I want to enter a date in the closingDate that mimics the now() function which is inserted correctly. Here is the closest i have got to insert at least something that looks promissing.

TOPICS
Advanced techniques

Views

406

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Nov 27, 2006 Nov 27, 2006

Copy link to clipboard

Copied

I have had major problems with dates as well. I think because were using the european format.
First, you don't need the createodbcddatetime in the cfparam, you have already done this above it.
I have tried setting the locale and all other thinks with no luck, so this is what I do now.

I make sure that the date can only be entered into the form field with a particular format (dd/mm/yyyy)
I check this both at the client and the server.

I then pull the form field apart in the createdatetime function, note I also do this if the time values are passed in the form as well.

Ken

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 28, 2006 Nov 28, 2006

Copy link to clipboard

Copied

Thanks for the prompt reply Ken.
However it does not work for me. Maybe I haven't explained it well.
When I code it as you have suggested, the isert statement will not insert the hh:mm:ss - and it will round the date up - so for example if I have 28/11/2006 23:59:59 it will round it up to 29/11/2006 in the field (note - no time). I do not want this - I want this to be exactly as I have specified it above. I have noticed that the now() function is entered in such format only if you do not use the cfqueryparam. It will not work in the same way with the above variable because it is a string (don't judge for having tried it - I am getting desperate).

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 28, 2006 Nov 28, 2006

Copy link to clipboard

Copied

Well I've found the problem.
I've been inserting a date and time which actually gets rounded up/down to the nearest 30 seconds. For example:

28/11/2006 23:59:59 would be rounded up to 29/11/2006 00:00:00 but the 00:00:00 would not show because frankly they are zero's (i.e. trailing zero’s).

I’ve noticed that if I put 28/11/2006 23:59:29 it will round it down to 28/11/2006 23:59:00

This way I am losing only one minute, which for my application, is not that drastic.

It seems like CF does not cater for precise times. I may be wrong but this is what I’ve found in my environment and if anyone knows better then please let me know.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 28, 2006 Nov 28, 2006

Copy link to clipboard

Copied

Right!

I poked a bit further and I think the problem is not with CF - it is with MsSQL. It is MsSQL that rounds numbers up/down.
http://support.microsoft.com/kb/135861/en-us

This seems to happen even with milliseconds - i.e. 999 is rounded up by 1 which has the 'reverse domino effect' on the date/time.

Not that I need it, but for curiosity sake, how does CF handle milliseconds? Or does it?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Nov 28, 2006 Nov 28, 2006

Copy link to clipboard

Copied

I have never had this problem, but I have not needed to use milliseconds either.
But the MS article indicates that this should only happen if the millisecond is 999.
Thus it should not round down as you have indicated.
What version of MS SQl Server and level of patch have you installed ?

After looking at the CF function for date/time it would appear that CF only goes to seconds.

Ken

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 30, 2006 Nov 30, 2006

Copy link to clipboard

Copied

I am running MsSQL 2k running on winXP Prof with Service Pack 2 on my local machine.
The same is installed on the server running win2k Server.

I don't think for the sake of the application that I am developing I need milliseconds, but I was getting curious. If I lose a minute for the closingDate then so be it. Maybe I will get back to it when I have a bit more time.

On another note, is there a way of getting the date given the week of the year? I want to find out the dates Monday to Friday given the week and the year.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Nov 30, 2006 Nov 30, 2006

Copy link to clipboard

Copied

LATEST
Just a point to note.

If you installed winXP sp2 after you installed sql server 2k sp 4 then you will need to install sql server 2k sp 4 again.

quote:

On another note, is there a way of getting the date given the week of the year?


Yes, but off hand I could not tell you how.

Ken

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation