| View previous topic :: View next topic |
| Author |
Message |
Zaboss Coffee Addict!

Joined: 23 Oct 2002 Posts: 786 Location: .ro
|
Posted: Mon Jan 10, 2005 8:05 pm Post subject: A problem with dates |
|
|
I have discovered a strange bug in one of my applications.
The user is supposed to do some jobs, for which he has a deadline, which is the 7th of every month. After that day, he shouldn't be able to perform some actions. The code is:
| Code: |
If Day(Now()) > "7" then
If Month(thefields3(2)) < Month(Now()) then
...
|
Well, everything worked fine, until this month, when it no longer works, because january it is not interpreted as following december... I have checked, and for february it works. So, it's only about 7th of january... Am I making any sense here? Does anybody have a clue for this? _________________ Zaboss
Design for web/print |
|
| Back to top |
|
 |
gruff Sleep Typist

Joined: 06 Nov 2004 Posts: 1132 Location: Glos.
|
Posted: Mon Jan 10, 2005 8:51 pm Post subject: |
|
|
Hi
A good starting point is to check that you have a
Session.LCID defined in the the global.asa.
Otherwise date formats take the default of the Server which may change!
G |
|
| Back to top |
|
 |
Zaboss Coffee Addict!

Joined: 23 Oct 2002 Posts: 786 Location: .ro
|
Posted: Tue Jan 11, 2005 7:16 am Post subject: |
|
|
I don't think it has somethin to do with this. But onŁy with December = 12 and January = 1 and 1 < 12 while in any otherr cases the previous month = (current month) - 1. _________________ Zaboss
Design for web/print |
|
| Back to top |
|
 |
gruff Sleep Typist

Joined: 06 Nov 2004 Posts: 1132 Location: Glos.
|
Posted: Tue Jan 11, 2005 8:03 am Post subject: |
|
|
Maybe,
I notice that you have a "7" which implies that 7 is a string which is different from 7.
| Code: |
Or try something like:-
if day(now()) > 7 then
if cint(Month(thfields3(2))) > cint(Month(now()) then
....
|
Yo get the idea.
G |
|
| Back to top |
|
 |
Zaboss Coffee Addict!

Joined: 23 Oct 2002 Posts: 786 Location: .ro
|
Posted: Tue Jan 11, 2005 8:46 am Post subject: |
|
|
It doesn't work either, because it stil compares 1 with 12. I need somehow to get the year in this picture. The problem is that I want ot avoid a big if/else here. _________________ Zaboss
Design for web/print |
|
| Back to top |
|
 |
Paul Creedy Sleep Typist
Joined: 19 Jun 2002 Posts: 1238 Location: Rhondda Cynon Taff South Wales UK
|
|
| Back to top |
|
 |
gruff Sleep Typist

Joined: 06 Nov 2004 Posts: 1132 Location: Glos.
|
Posted: Tue Jan 11, 2005 12:30 pm Post subject: |
|
|
Oh I see what you mean, I should have fully understood the problem before answering.......
Why not include the year in the comparision too? But put it first.
0412 and 0501
I am sure that there must be a better way.......  |
|
| Back to top |
|
 |
Nick Forum Moderator

Joined: 18 Jun 2002 Posts: 3635
|
Posted: Tue Jan 11, 2005 1:18 pm Post subject: |
|
|
Yes, I think using the year is the best solution here.
After years of being pushed around by disagreeable dates when moving sites between servers/locations/date formats, I now use a tried and tested method of "yyyymmddhhmmss". Stored as an integer in the database, simple less than/greater than calculations can be performed, and it makes selecting records between two dates very easy.
I have one function to create an integer in the above format, and another couple to read them and format the number into whatever format I need. Maybe a useful article for Home@OH. The beauty of it is that it works no matter what date format the server uses. _________________ Nick Dunn
Nick Dunn |
|
| Back to top |
|
 |
Paul Creedy Sleep Typist
Joined: 19 Jun 2002 Posts: 1238 Location: Rhondda Cynon Taff South Wales UK
|
|
| Back to top |
|
 |
Mark Voss Divine Being

Joined: 19 Jun 2002 Posts: 4946 Location: Cardiff, UK
|
Posted: Tue Jan 11, 2005 1:30 pm Post subject: |
|
|
| Nick wrote: | | I now use a tried and tested method of "yyyymmddhhmmss". Stored as an integer in the database, simple less than/greater than calculations can be performed, and it makes selecting records between two dates very easy. |
Excellent idea Nick  _________________ Mark Voss
http://www.markvoss.net |
|
| Back to top |
|
 |
Nick Forum Moderator

Joined: 18 Jun 2002 Posts: 3635
|
Posted: Tue Jan 11, 2005 1:39 pm Post subject: |
|
|
| Mark Voss wrote: | | Nick wrote: | | I now use a tried and tested method of "yyyymmddhhmmss". Stored as an integer in the database, simple less than/greater than calculations can be performed, and it makes selecting records between two dates very easy. |
Excellent idea Nick  |
There you go. _________________ Nick Dunn
Nick Dunn |
|
| Back to top |
|
 |
Zaboss Coffee Addict!

Joined: 23 Oct 2002 Posts: 786 Location: .ro
|
Posted: Tue Jan 11, 2005 2:00 pm Post subject: |
|
|
Actualy, it's not from database, but from a text file over which i have but little control. So I have to deal with it as it is. I have found a simple workarround:
| Code: |
theMonth = Month (date)
if theMonth = 1 then
theMonth = 13
else
theMonth = Month (date)
end if
|
_________________ Zaboss
Design for web/print |
|
| Back to top |
|
 |
Nick Forum Moderator

Joined: 18 Jun 2002 Posts: 3635
|
Posted: Tue Jan 11, 2005 2:06 pm Post subject: |
|
|
| Zaboss wrote: | | Actualy, it's not from database, but from a text file |
They're both databases. Are you sure you can't grab the year from the text file as well as the month?
Glad you found a workaround, but surely that works only for the difference between December and January (of different years) and not January to February of the same year.
Still, if it works, it works  _________________ Nick Dunn
Nick Dunn |
|
| Back to top |
|
 |
Zaboss Coffee Addict!

Joined: 23 Oct 2002 Posts: 786 Location: .ro
|
Posted: Tue Jan 11, 2005 2:34 pm Post subject: |
|
|
It works for february to january... And I only need one month difference, because, for instance, there is no point for him to perform some operations pertaining november, since the activities for november were checked on 8th of december. So there is no need for him to try to do them in january (where the validation rule doesn't work for november, or for any month of the previous year, for that matter). So, the only thing that interest me is just the previous month and for that it works now for all months. _________________ Zaboss
Design for web/print |
|
| Back to top |
|
 |
Mzebonga Forum Moderator

Joined: 12 Jan 2003 Posts: 3484 Location: Gloucester, UK
|
Posted: Tue Jan 11, 2005 4:50 pm Post subject: |
|
|
Why not make a compound variable from the month AND the year?
| Code: | Right Then = Year(thefields3(2)) & Month(thefields3(2))
RightNow = Year(Now()) & Month(Now())
If RightThen < RightNow then |
Or something to that effect.
That way that way, January of the next year would always be a bigger variable... _________________ Mzebonga |
|
| Back to top |
|
 |
|