SearchSearch   MemberlistMembers   RegisterRegister   ProfileProfile   Log inLog in 

A problem with dates

 
Post new topic   Reply to topic    Open Hosting Internet Solutions Forum Index -> ASP and ASP.NET Development Help
View previous topic :: View next topic  
Author Message
Zaboss
Coffee Addict!


Joined: 23 Oct 2002
Posts: 786
Location: .ro

PostPosted: Mon Jan 10, 2005 8:05 pm    Post subject: A problem with dates Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
gruff
Sleep Typist


Joined: 06 Nov 2004
Posts: 1132
Location: Glos.

PostPosted: Mon Jan 10, 2005 8:51 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
Zaboss
Coffee Addict!


Joined: 23 Oct 2002
Posts: 786
Location: .ro

PostPosted: Tue Jan 11, 2005 7:16 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
gruff
Sleep Typist


Joined: 06 Nov 2004
Posts: 1132
Location: Glos.

PostPosted: Tue Jan 11, 2005 8:03 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail
Zaboss
Coffee Addict!


Joined: 23 Oct 2002
Posts: 786
Location: .ro

PostPosted: Tue Jan 11, 2005 8:46 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
Paul Creedy
Sleep Typist


Joined: 19 Jun 2002
Posts: 1238
Location: Rhondda Cynon Taff South Wales UK

PostPosted: Tue Jan 11, 2005 12:29 pm    Post subject: Reply with quote

What you mean is Jan 2005 is AFTER Dec 2004?

You will need to bring the whole date into the formula so that it knows which year you are refering to:

Dec 2004 is AFTER Jan 2004, but Jan 2005 is AFTER Dec 2004

etc.
_________________
Paul Creedy
Admin@RhonddaCynonTaff.com

www.TreorchyComputerClinic.co.uk | www.PrincessHouse-Christine.co.uk | www.RhonddaCynonTaff.com | www.completerugby.com | www.richieburnett.com | www.TDGS.org.uk | www.RCTBroadband.com| www.CPDCymru.net |
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
gruff
Sleep Typist


Joined: 06 Nov 2004
Posts: 1132
Location: Glos.

PostPosted: Tue Jan 11, 2005 12:30 pm    Post subject: Reply with quote

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....... Smile
Back to top
View user's profile Send private message Send e-mail
Nick
Forum Moderator


Joined: 18 Jun 2002
Posts: 3635

PostPosted: Tue Jan 11, 2005 1:18 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website MSN Messenger
Paul Creedy
Sleep Typist


Joined: 19 Jun 2002
Posts: 1238
Location: Rhondda Cynon Taff South Wales UK

PostPosted: Tue Jan 11, 2005 1:27 pm    Post subject: Reply with quote

I do similar. I still store in the Date Field type not an integer, but I throw the date at the field in the format yyyy/mm/dd this way you can be guarenteed that whatever server or local you are in the date will get stored correctly.

ASP incorrectly reformats dates when you are using cross local servers. Server in US, user in UK etc. Using the above it works whatever.

You can also get the difference between two dates by using the DateDiff function.
_________________
Paul Creedy
Admin@RhonddaCynonTaff.com

www.TreorchyComputerClinic.co.uk | www.PrincessHouse-Christine.co.uk | www.RhonddaCynonTaff.com | www.completerugby.com | www.richieburnett.com | www.TDGS.org.uk | www.RCTBroadband.com| www.CPDCymru.net |
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
Mark Voss
Divine Being


Joined: 19 Jun 2002
Posts: 4946
Location: Cardiff, UK

PostPosted: Tue Jan 11, 2005 1:30 pm    Post subject: Reply with quote

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 Very Happy
_________________
Mark Voss
http://www.markvoss.net
Back to top
View user's profile Send private message Visit poster's website
Nick
Forum Moderator


Joined: 18 Jun 2002
Posts: 3635

PostPosted: Tue Jan 11, 2005 1:39 pm    Post subject: Reply with quote

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 Very Happy

There you go.
_________________
Nick Dunn
Nick Dunn
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Zaboss
Coffee Addict!


Joined: 23 Oct 2002
Posts: 786
Location: .ro

PostPosted: Tue Jan 11, 2005 2:00 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
Nick
Forum Moderator


Joined: 18 Jun 2002
Posts: 3635

PostPosted: Tue Jan 11, 2005 2:06 pm    Post subject: Reply with quote

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 Smile
_________________
Nick Dunn
Nick Dunn
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Zaboss
Coffee Addict!


Joined: 23 Oct 2002
Posts: 786
Location: .ro

PostPosted: Tue Jan 11, 2005 2:34 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
Mzebonga
Forum Moderator


Joined: 12 Jan 2003
Posts: 3484
Location: Gloucester, UK

PostPosted: Tue Jan 11, 2005 4:50 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Open Hosting Internet Solutions Forum Index -> ASP and ASP.NET Development Help All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB 2.0.11 © 2001, 2002 phpBB Group
FAQClick here for help using the phpBB forum