473,386 Members | 1,830 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

asp date function for past dates only

229 100+
Hi, I wonder if anyone can help.
I have a query like this

Expand|Select|Wrap|Line Numbers
  1. <%
  2. If  datediff("d", [PDnewsfield],  now())  < 21  Then
  3. %> 
  4. <a target=_blank title="blog" href="news</a>
  5. <%
  6. Else
  7. %> 
  8. <%
  9. End If
  10. %> 
I am working with an access 2000 database and the date function is written in general format like 19/08/2009 22:27:20

I have an input field with a date picker so a user in their control panel can select a date in the future and in the past for a news event. I want news event to show on the website from the date they choose and for 21 days after that date only. This code I have above is fine in another context but if a user picks a date in the future it will show it when I dont want it to. If anyone can point me to the function I would need that would be great.
Thanks
Richard
Aug 15 '09 #1
11 2978
fran7
229 100+
Hi, I am sorry I think I havent explained well. I need an if clause to say

if date in field "PDnewsfield" = todays date
then
show content "PDnewsfieldcontent"
and for only 21 days after the date.

Thanks for any advice
Richard
Aug 16 '09 #2
jhardman
3,406 Expert 2GB
I'm not 100% sure I follow you, but I think you just need to replace "now()" with an expression for the date in the future you wanted to look at. Does this make sense?

Jared
Aug 17 '09 #3
fran7
229 100+
Hi Jared, I have a news and a date field in my database. I need the news to appear on the webpage only when the date in the date field = now()
and to only appear for 21 days after the date in the date field.
I have looked at dateadd and datedif functions. This gets me the news but I need to show for only 21 days before it doesnt show anymore. I dont know if thats any clearer or you can suggest which combinations of functions I would need.
<%
If (Now) = RS("date") Then
%>
display news
<%
Else
%>
<%
End If
%>
Thanks
Richard
Aug 17 '09 #4
fran7
229 100+
Hi, I think I worked it out. This seems to do the trick.
<%
strDate = Date()
If (Date) <= RS("mynewsdate") and DateDiff("d", strDate, rs("mynewsdate") ) < 21 then
%>
news
<%
Else
%>
<%
End If
%>
Thanks for your advice
Richard
Aug 18 '09 #5
fran7
229 100+
Hi, Had to get back. It works fine but now I have a problem with the database and inputting the date. I changed the field to a date and time field and it threw up problems. It works fine if there is a date to submit but if left blank it throws up type mismatch. I have the date field as "not required" so not sure why this might be. Tried many tinkerings to no avail.

The form field is like this
Expand|Select|Wrap|Line Numbers
  1. Response.Write "<input type=""text"" name=""PDimageninemedium"" value=""" & objGetPersonalProfileOnEdit("PDimageninemedium") & """ size=""30"" maxlength=""30"">"
and I just wonder if I need to add something to show its a date being entered as 1. when I had the database field as a text field it worked fine.
2. if I cut the time of the end of the date its fine but if I cut some of the date itself it throws up the same error again.

Thank makes me think its a database thing but the field is set at not required so bit at a loss.
Any ideas would be great
Thanks
Richard
Aug 18 '09 #6
jhardman
3,406 Expert 2GB
hmm. Never had that problem before, sounds like it's db-specific. You said you are using access? I'll ask an access expert to weigh in.

Jared
Aug 21 '09 #7
fran7
229 100+
Dear jared, Yes I looked around and it seems that entering null in a date field throws up errors. I worked around it by making it a required field at the user end so they dont get to see the error as they have to input a date regardless. It seemed to complicated for me to make the code accept null values as there seemed to be solutions in that respect.
Thanks for your help
Richard
Aug 21 '09 #8
NeoPa
32,556 Expert Mod 16PB
Can you say what the Required property is set to for that field in your database?

If it is set to Yes then that may well explain your difficulty.
Aug 21 '09 #9
Frinavale
9,735 Expert Mod 8TB
I don't know the answer to your problem but I know what's happening.

Null in your code is not MS Access's "null".

.NET has figured out a way to get around this.

In .NET there is the DBNull Object. This Object can be used to determine if NULL was returned by the database it's connecting to (whether it be MS Access, MySQL, or MS SQL). You can also use this object to supply NULL to the database you're connecting to.

(In .NET you use the DBNull.Value to supply "null" to the database that you're using. )


You need to find a way to supply an "MS Access" null to the database.

-Frinny
Aug 21 '09 #10
there are many many places whee you can study .NET, i am a software programmer, i do JAVA
you can try, code project or msdn to get the codes sorted
Aug 22 '09 #11
fran7
229 100+
Thanks guys, I have adapted already written code so I think frinny you are right, I will have to look into that further.
Thanks a lot for all your advice.
Richard
Aug 22 '09 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

13
by: perplexed | last post by:
How do you convert a user inputted date to a unix timestamp before insterting it into your database? I have a form, with a textfield for a date that the user inputs in the format mm-dd-yyyy and...
2
by: androtech | last post by:
Hello, I'm looking for a function that returns a date range for a specified week number of the year. I'm not able to find functions like this anywhere. Any pointers/help would be much...
16
by: sandy | last post by:
Hi, Using Java script I am trying to create code where when you place in the start date it automatically calculates 6 months for the experations date. For example when I place 01/01/04 as the...
7
by: Mick White | last post by:
According to the Safari browser the world began on "Fri Dec 13 1901 15:45:52 GMT-0500", but I need to be able to get around this limitation. I am interested in dates from 1500 to 1901, as far as...
3
by: Joel | last post by:
I recently converted data and discovered that when the date wasn't formatted properly '01/01/001' (I think) that I was unable to find the record using Sql i.e 'Select * from table where...
3
by: www.ttdown.com | last post by:
Each day a user is supposed to import a list of information into a database table. The user only has 30 days to import this information. After 30 days the information is lost. I need to be able...
0
yasirmturk
by: yasirmturk | last post by:
Standard Date and Time Functions The essential date and time functions that every SQL Server database should have to ensure that you can easily manipulate dates and times without the need for any...
3
by: murch.alexander | last post by:
I made a simple public function to set and return a date value (see below). I have a number of queries that call up the function to get the "As Of Date," which is typically set to today's date....
4
by: OzNet | last post by:
I have some functions to calculate the working days in a given period. This includes a table that is queried to calculate the number of public holidays that don’t occur on a weekend. If I test...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.