Showing posts with label date. Show all posts
Showing posts with label date. Show all posts

Wednesday, March 28, 2012

Subtract days from a Date

How can I code my app to get this date:

11/1/2203

From this date:

11/15/2003

I need to Subtract 14 days from 11/15/2003 but I am not sure to go about doing this.

ThanksThis may help

Dim dteNewDate As Date
Dim dteOldDate As Date = "01/01/03"
Dim intNoOfDays As Int16 = 11

dteNewDate = DateAdd("d", -intNoOfDays, dteOldDate)

TextBox1.Text = dteNewDate
The easiest way to do this is to pass a negative number into Date.AddDays(). I was able to perform the transformation you described using the following code:


Private Sub Calendar1_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Calendar1.SelectionChanged
Label1.Text = Calendar1.SelectedDate.AddDays(-14)
End Sub

(This code should be run on a page with a Label and Calendar control if you want to try it out.)

Hope this helps.
<%
Dim dtmDate As DateTime
dtmDate = DateTime.Now()

Response.Write( dtmDate.ToString( "d" ) )

Dim AdddtmDate As DateTime

AdddtmDate = dtmDate.addDays(-14)

Response.write ("<br>")
Response.write (AdddtmDate)
%>
We recently wrote a simpletutorial example on working with Dates & Time in ASP.NET

Clay is right - just pass a negative number.

Bringing this back up. I found the information here very useful.

Can anyone tell me if there is a way to get what the last day of the month is? Like if the month is Febuary, I need to be able to detect 28 and 31 for March...


I don't think there is anything built in to get the last day of the month but you can use this little piece of code to get the last day of the month.

privateDateTime getLastDayOfMonth(DateTime d)

{

//get the first day of this month

int days = (d.Day - 1) * -1;

d = d.AddDays(days);

// add a month to this date

d = d.AddMonths(1);

d=d.AddDays(-1);

return d;

}

  

Subtracting Date in VB.Net

Need Help!

How do I write the following expression for my project limiting the number of entries on my datagrid by 30 days from Now():

<!--

SELECT * FROM tblGrid WHERE dateEntered between Now() - 30 and Now()

-->

note: dateEntered are the dates in my date field (mm-dd-yyyy)

Thanks a lot.

If you are using VB.NET, you can use DateTime.Add method. There's an exampe in the docs here:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdatetimeclassaddtopic.asp

Subtracting from a Date

Hello,

In .NET code, I need to subtract a month from the current date; is there something in the framework that does this; there is some care that is needed to do this, especially with 28-day and 30-day months, so I was wondering if there was something built-in.

Thanks.

If I understand you question right you could do this:

DateTime dtTemp = DateTime.Now;

int Month = dtTemp.Month;

Cheers

Al


Dim dAs DateTime

d = DateTime.Now

d = d.AddMonths(-1)


If you write VB.NET try the link below for DateDiff function a clone of the T-SQL version. Hope this helps.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vblr7/html/vafctdatediff.asp


Hello,

Try it:

Dim LastMonth As Date = DateAdd(DateInterval.Month, -1, #3/27/2006#)

You'll found this function under following namespace:
Microsoft.VisualBasic

An this will solve your problem related to 28-days/30-days. Functions takes care of this.

Regards

Kuldeep Deokule

subtracting days from date

hI,
i AM TRYING TO SUBTRACT DAYS FROM PARTICULAR DATE. i KEEP GETTING THE ERROR:
hERE IS MY CODE: enddatecriteria=tempDate.AddDays(30);
startdatecriteria=tempDate.AddDays(-30);
I AM USING C# AND THE ERROR IS:
Ticks must be between DateTime.MinValue.Ticks and DateTime.MaxValue.Ticks.
Parameter name: ticks
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information abou
t
the error and where it originated in the code.
Exception Details: System.ArgumentOutOfRangeException: Ticks must be between
DateTime.MinValue.Ticks and DateTime.MaxValue.Ticks. Parameter name: ticks
Source Error:
cAN SOMEONE HELPtempDate = System.DateTime.Now;
enddatecriteria=tempDate.AddDays(30);
startdatecriteria=tempDate.AddDays(-30);
"Manny Chohan" wrote:

> hI,
> i AM TRYING TO SUBTRACT DAYS FROM PARTICULAR DATE. i KEEP GETTING THE ERRO
R:
> hERE IS MY CODE: enddatecriteria=tempDate.AddDays(30);
> startdatecriteria=tempDate.AddDays(-30);
> I AM USING C# AND THE ERROR IS:
> Ticks must be between DateTime.MinValue.Ticks and DateTime.MaxValue.Ticks.
> Parameter name: ticks
> Description: An unhandled exception occurred during the execution of the
> current web request. Please review the stack trace for more information ab
out
> the error and where it originated in the code.
> Exception Details: System.ArgumentOutOfRangeException: Ticks must be betwe
en
> DateTime.MinValue.Ticks and DateTime.MaxValue.Ticks. Parameter name: ticks
> Source Error:
> cAN SOMEONE HELP
my complete code is follows:
tempDate=Convert.ToDateTime(Calendar2.TodaysDate.ToShortDateString());
enddatecriteria=tempDate.AddDays(30);
startdatecriteria=tempDate.AddDays(-30);
It still give me error. I am using c#.
Thanks
Manny
"vinay" wrote:
> tempDate = System.DateTime.Now;
> enddatecriteria=tempDate.AddDays(30);
> startdatecriteria=tempDate.AddDays(-30);
>
> "Manny Chohan" wrote:
>
Which event are you checking the values'
post the full code.
"Manny Chohan" wrote:
> my complete code is follows:
> tempDate=Convert.ToDateTime(Calendar2.TodaysDate.ToShortDateString());
> enddatecriteria=tempDate.AddDays(30);
> startdatecriteria=tempDate.AddDays(-30);
> It still give me error. I am using c#.
> Thanks
> Manny
> "vinay" wrote:
>
thanks Vinay, here is the code:
if(!Page.IsPostBack)
{
Get_Appointments();
tempDate=Convert.ToDateTime(Calendar2.TodaysDate.ToShortDateString());
}
public void MonthChanged(object sender, MonthChangedEventArgs e)
{
//Set the tempDatevariable to the value in the MonthChangedEventArgs
NewDate property
tempDate = e.NewDate;
//Reload the collection
Get_Appointments();
}
ICollection Get_Appointments()
{
DateTime startDate = new DateTime(2004,11,1);
DateTime endDate = new DateTime(2004,12,1);
enddatecriteria=tempDate.AddDays(30);
startdatecriteria=tempDate.AddDays(-30);
Rest follows the custom code as i am working with vendor API. Please let me
know if this is enough.
Thanks
Manny
"vinay" wrote:
> Which event are you checking the values'
> post the full code.
> "Manny Chohan" wrote:
>
Manny, looks like your tempdate is empty when you do the startdatecriteria=
(you're trying to back off 30 days from what's already the date.minvalue).
I'd trace backwards from there and look at calendar2.todaysdate and
e.newdate. hth
"Manny Chohan" wrote:
> thanks Vinay, here is the code:
> if(!Page.IsPostBack)
> {
> Get_Appointments();
> tempDate=Convert.ToDateTime(Calendar2.TodaysDate.ToShortDateString()
);
> }
> public void MonthChanged(object sender, MonthChangedEventArgs e)
> {
> //Set the tempDatevariable to the value in the MonthChangedEventArgs
> NewDate property
> tempDate = e.NewDate;
> //Reload the collection
> Get_Appointments();
> }
> ICollection Get_Appointments()
> {
> DateTime startDate = new DateTime(2004,11,1);
> DateTime endDate = new DateTime(2004,12,1);
> enddatecriteria=tempDate.AddDays(30);
> startdatecriteria=tempDate.AddDays(-30);
> Rest follows the custom code as i am working with vendor API. Please let m
e
> know if this is enough.
> Thanks
> Manny
>
> "vinay" wrote:
>

subtracting days from date

hI,
i AM TRYING TO SUBTRACT DAYS FROM PARTICULAR DATE. i KEEP GETTING THE ERROR:
hERE IS MY CODE: enddatecriteria=tempDate.AddDays(30);
startdatecriteria=tempDate.AddDays(-30);
I AM USING C# AND THE ERROR IS:
Ticks must be between DateTime.MinValue.Ticks and DateTime.MaxValue.Ticks.
Parameter name: ticks
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.

Exception Details: System.ArgumentOutOfRangeException: Ticks must be between
DateTime.MinValue.Ticks and DateTime.MaxValue.Ticks. Parameter name: ticks

Source Error:

cAN SOMEONE HELPtempDate = System.DateTime.Now;
enddatecriteria=tempDate.AddDays(30);
startdatecriteria=tempDate.AddDays(-30);

"Manny Chohan" wrote:

> hI,
> i AM TRYING TO SUBTRACT DAYS FROM PARTICULAR DATE. i KEEP GETTING THE ERROR:
> hERE IS MY CODE: enddatecriteria=tempDate.AddDays(30);
> startdatecriteria=tempDate.AddDays(-30);
> I AM USING C# AND THE ERROR IS:
> Ticks must be between DateTime.MinValue.Ticks and DateTime.MaxValue.Ticks.
> Parameter name: ticks
> Description: An unhandled exception occurred during the execution of the
> current web request. Please review the stack trace for more information about
> the error and where it originated in the code.
> Exception Details: System.ArgumentOutOfRangeException: Ticks must be between
> DateTime.MinValue.Ticks and DateTime.MaxValue.Ticks. Parameter name: ticks
> Source Error:
> cAN SOMEONE HELP
my complete code is follows:
tempDate=Convert.ToDateTime(Calendar2.TodaysDate.T oShortDateString());

enddatecriteria=tempDate.AddDays(30);
startdatecriteria=tempDate.AddDays(-30);
It still give me error. I am using c#.
Thanks
Manny

"vinay" wrote:

> tempDate = System.DateTime.Now;
> enddatecriteria=tempDate.AddDays(30);
> startdatecriteria=tempDate.AddDays(-30);
>
> "Manny Chohan" wrote:
> > hI,
> > i AM TRYING TO SUBTRACT DAYS FROM PARTICULAR DATE. i KEEP GETTING THE ERROR:
> > hERE IS MY CODE: enddatecriteria=tempDate.AddDays(30);
> > startdatecriteria=tempDate.AddDays(-30);
> > I AM USING C# AND THE ERROR IS:
> > Ticks must be between DateTime.MinValue.Ticks and DateTime.MaxValue.Ticks.
> > Parameter name: ticks
> > Description: An unhandled exception occurred during the execution of the
> > current web request. Please review the stack trace for more information about
> > the error and where it originated in the code.
> > Exception Details: System.ArgumentOutOfRangeException: Ticks must be between
> > DateTime.MinValue.Ticks and DateTime.MaxValue.Ticks. Parameter name: ticks
> > Source Error:
> > cAN SOMEONE HELP
Which event are you checking the values??
post the full code.

"Manny Chohan" wrote:

> my complete code is follows:
> tempDate=Convert.ToDateTime(Calendar2.TodaysDate.T oShortDateString());
> enddatecriteria=tempDate.AddDays(30);
> startdatecriteria=tempDate.AddDays(-30);
> It still give me error. I am using c#.
> Thanks
> Manny
> "vinay" wrote:
> > tempDate = System.DateTime.Now;
> > enddatecriteria=tempDate.AddDays(30);
> > startdatecriteria=tempDate.AddDays(-30);
> > "Manny Chohan" wrote:
> > > hI,
> > > i AM TRYING TO SUBTRACT DAYS FROM PARTICULAR DATE. i KEEP GETTING THE ERROR:
> > > hERE IS MY CODE: enddatecriteria=tempDate.AddDays(30);
> > > startdatecriteria=tempDate.AddDays(-30);
> > > I AM USING C# AND THE ERROR IS:
> > > Ticks must be between DateTime.MinValue.Ticks and DateTime.MaxValue.Ticks.
> > > Parameter name: ticks
> > > Description: An unhandled exception occurred during the execution of the
> > > current web request. Please review the stack trace for more information about
> > > the error and where it originated in the code.
> > > > Exception Details: System.ArgumentOutOfRangeException: Ticks must be between
> > > DateTime.MinValue.Ticks and DateTime.MaxValue.Ticks. Parameter name: ticks
> > > > Source Error:
> > > > cAN SOMEONE HELP
thanks Vinay, here is the code:

if(!Page.IsPostBack)
{
Get_Appointments();
tempDate=Convert.ToDateTime(Calendar2.TodaysDate.T oShortDateString());

}
public void MonthChanged(object sender, MonthChangedEventArgs e)
{
//Set the tempDatevariable to the value in the MonthChangedEventArgs
NewDate property
tempDate = e.NewDate;
//Reload the collection
Get_Appointments();
}

ICollection Get_Appointments()
{

DateTime startDate = new DateTime(2004,11,1);
DateTime endDate = new DateTime(2004,12,1);

enddatecriteria=tempDate.AddDays(30);
startdatecriteria=tempDate.AddDays(-30);

Rest follows the custom code as i am working with vendor API. Please let me
know if this is enough.

Thanks

Manny

"vinay" wrote:

> Which event are you checking the values??
> post the full code.
> "Manny Chohan" wrote:
> > my complete code is follows:
> > tempDate=Convert.ToDateTime(Calendar2.TodaysDate.T oShortDateString());
> > enddatecriteria=tempDate.AddDays(30);
> > startdatecriteria=tempDate.AddDays(-30);
> > It still give me error. I am using c#.
> > Thanks
> > Manny
> > "vinay" wrote:
> > > tempDate = System.DateTime.Now;
> > > enddatecriteria=tempDate.AddDays(30);
> > > startdatecriteria=tempDate.AddDays(-30);
> > > > > "Manny Chohan" wrote:
> > > > > hI,
> > > > i AM TRYING TO SUBTRACT DAYS FROM PARTICULAR DATE. i KEEP GETTING THE ERROR:
> > > > hERE IS MY CODE: enddatecriteria=tempDate.AddDays(30);
> > > > startdatecriteria=tempDate.AddDays(-30);
> > > > I AM USING C# AND THE ERROR IS:
> > > > Ticks must be between DateTime.MinValue.Ticks and DateTime.MaxValue.Ticks.
> > > > Parameter name: ticks
> > > > Description: An unhandled exception occurred during the execution of the
> > > > current web request. Please review the stack trace for more information about
> > > > the error and where it originated in the code.
> > > > > > Exception Details: System.ArgumentOutOfRangeException: Ticks must be between
> > > > DateTime.MinValue.Ticks and DateTime.MaxValue.Ticks. Parameter name: ticks
> > > > > > Source Error:
> > > > > > cAN SOMEONE HELP
Manny, looks like your tempdate is empty when you do the startdatecriteria=
(you're trying to back off 30 days from what's already the date.minvalue).
I'd trace backwards from there and look at calendar2.todaysdate and
e.newdate. hth

"Manny Chohan" wrote:

> thanks Vinay, here is the code:
> if(!Page.IsPostBack)
> {
> Get_Appointments();
> tempDate=Convert.ToDateTime(Calendar2.TodaysDate.T oShortDateString());
> }
> public void MonthChanged(object sender, MonthChangedEventArgs e)
> {
> //Set the tempDatevariable to the value in the MonthChangedEventArgs
> NewDate property
> tempDate = e.NewDate;
> //Reload the collection
> Get_Appointments();
> }
> ICollection Get_Appointments()
> {
> DateTime startDate = new DateTime(2004,11,1);
> DateTime endDate = new DateTime(2004,12,1);
> enddatecriteria=tempDate.AddDays(30);
> startdatecriteria=tempDate.AddDays(-30);
> Rest follows the custom code as i am working with vendor API. Please let me
> know if this is enough.
> Thanks
> Manny
>
> "vinay" wrote:
> > Which event are you checking the values??
> > post the full code.
> > "Manny Chohan" wrote:
> > > my complete code is follows:
> > > tempDate=Convert.ToDateTime(Calendar2.TodaysDate.T oShortDateString());
> > > > enddatecriteria=tempDate.AddDays(30);
> > > startdatecriteria=tempDate.AddDays(-30);
> > > It still give me error. I am using c#.
> > > Thanks
> > > Manny
> > > > "vinay" wrote:
> > > > > tempDate = System.DateTime.Now;
> > > > enddatecriteria=tempDate.AddDays(30);
> > > > startdatecriteria=tempDate.AddDays(-30);
> > > > > > > > "Manny Chohan" wrote:
> > > > > > > hI,
> > > > > i AM TRYING TO SUBTRACT DAYS FROM PARTICULAR DATE. i KEEP GETTING THE ERROR:
> > > > > hERE IS MY CODE: enddatecriteria=tempDate.AddDays(30);
> > > > > startdatecriteria=tempDate.AddDays(-30);
> > > > > I AM USING C# AND THE ERROR IS:
> > > > > Ticks must be between DateTime.MinValue.Ticks and DateTime.MaxValue.Ticks.
> > > > > Parameter name: ticks
> > > > > Description: An unhandled exception occurred during the execution of the
> > > > > current web request. Please review the stack trace for more information about
> > > > > the error and where it originated in the code.
> > > > > > > > Exception Details: System.ArgumentOutOfRangeException: Ticks must be between
> > > > > DateTime.MinValue.Ticks and DateTime.MaxValue.Ticks. Parameter name: ticks
> > > > > > > > Source Error:
> > > > > > > > cAN SOMEONE HELP

Thursday, March 22, 2012

Support Trouble ticket type deal

I'm trying to make a support ticket system, I would like to know

How would you display how many replies an issue hasthe date of the last replyThanks

What is your DB architecture like?

I would have 2 tables:
(1) Tickets which contains all ticket information such as title, issue, member who submitted the ticket, createDate, and TicketID.
(2) TicketReplies which contains all replies for a ticket, a createDate, and a foreign key TicketID.
You can set createDate default binding = getDate() which will return the current dateTime.

If you need to know how many replies there are for a ticket you can run:
SELECT COUNT(*)
FROM TicketReplies tr
JOIN Tickets t
ON tr.TicketID = t.TicketID
WHERE t.TicketID = (whatever the ticket is that you are interested in)

If you need to know the date of the last reply you can run:
SELECT *
FROM TicketReplies tr
JOIN Tickets t
ON tr.TicketID = t.TicketID
WHERE t.TicketID = (whatever the ticket is that you are interested in)
ORDER BY CreateDate DESC