Showing posts with label number. Show all posts
Showing posts with label number. Show all posts

Saturday, March 31, 2012

Subracting days from datetime?

I thought I could subract days from a DateTime instance by passing a negative number into the AddDays method. That doesn't seem to work however. Do I have the syntax right below
(its in c#)
DateTime maxDate = DateTime.Now;
maxDate.AddDays(-1);
// results in no days subtracted, still shows current day. arrrgh.
Does this work?

DateTime maxDate = DateTime.Now;

maxDate.Subtract( new TimeSpan( 24, 0, 0) );
Try: maxDate = maxDate.AddDays(-1);

Wednesday, March 28, 2012

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 two dates to get number of days between

How would i take two dates startdate and enddate and subtract startdate from
enddate to figure the number of days between the two? thanks["Followup-To:" header set to microsoft.public.dotnet.languages.vb.]
On 2003-11-19, Brian Henry <brianiup@.adelphia.net> wrote:
> How would i take two dates startdate and enddate and subtract startdate from
> enddate to figure the number of days between the two? thanks

Dim Difference As TimeSpan = enddate.Subtract(startdate)
Console.WriteLine(Difference.Days)

--
Tom Shelton
[MVP - Visual Basic]
neverminde :)

If DateDiff(DateInterval.Day, dbReader("sectionedited"), Now.Date) <= 30
Then

"Brian Henry" <brianiup@.adelphia.net> wrote in message
news:uEyFv6trDHA.2360@.TK2MSFTNGP10.phx.gbl...
> How would i take two dates startdate and enddate and subtract startdate
from
> enddate to figure the number of days between the two? thanks
Not sure what language you want, but the VB isn't much differen that this C#

DateTime d1, d2; // Make sure you assign these first

TimeSpan ts = d1-d2;

int days = ts.Days;

HTH
Brian W

"Brian Henry" <brianiup@.adelphia.net> wrote in message
news:uEyFv6trDHA.2360@.TK2MSFTNGP10.phx.gbl...
> How would i take two dates startdate and enddate and subtract startdate
from
> enddate to figure the number of days between the two? thanks
((start.Ticks - end.Ticks) / TimeSpan.TicksPerHour) /24;

"Brian Henry" <brianiup@.adelphia.net> wrote in message
news:uEyFv6trDHA.2360@.TK2MSFTNGP10.phx.gbl...
> How would i take two dates startdate and enddate and subtract startdate
from
> enddate to figure the number of days between the two? thanks
System.DateTime includes a Subtract method, which will do exactly this. In
C#, you can also use the - operator.

--
Chris Jackson
Software Engineer
Microsoft MVP - Windows Shell/UI
Windows XP Associate Expert
--
More people read the newsgroups than read my email.
Reply to the newsgroup for a faster response.
(Control-G using Outlook Express)
--

"Brian Henry" <brianiup@.adelphia.net> wrote in message
news:uEyFv6trDHA.2360@.TK2MSFTNGP10.phx.gbl...
> How would i take two dates startdate and enddate and subtract startdate
from
> enddate to figure the number of days between the two? thanks
when i do this

Dim diffNUmb As Integer = DateDiff(DateInterval.day,
dbReader.GetDateTime(dbReader.GetOrdinal("sectionedited")), Now())

the sectionedited attribute of the table in the dbreader being a datetime
with a date/time of #10/19/2003 12:00:00 AM# in it and i run it, every time
it will return 0 as the diffrence in days even though i change the month and
day in the fixed date... why would it do this? thanks

"Brian Henry" <brianiup@.adelphia.net> wrote in message
news:%23Ko5QBurDHA.540@.tk2msftngp13.phx.gbl...
> neverminde :)
> If DateDiff(DateInterval.Day, dbReader("sectionedited"), Now.Date) <= 30
> Then
>
> "Brian Henry" <brianiup@.adelphia.net> wrote in message
> news:uEyFv6trDHA.2360@.TK2MSFTNGP10.phx.gbl...
> > How would i take two dates startdate and enddate and subtract startdate
> from
> > enddate to figure the number of days between the two? thanks

Saturday, March 24, 2012

Sum result in Label field

I summed a column of numbers and would like to put them in a Label field to display the result. I understand the conversion for number to string, I don't understand how to that value, that has been summed, to do it.

thanks
grady

int x = 7;
int y = 7;
int z = x + y;

LabelID.Text = z.ToString();

Is that what you're looking for?

HTH,
Ryan


Actually I have summed a column called TFsum and I was trying to display that and it say it was undeclared.

Here is the SQL:
SELECT SUM(filesfailed) AS TFsum
FROM accmonreport
WHERE oa='ddlOA'
HAVING SUM(filesfailed)=0

ddlOA is a dropdown list in the first view on the page. I'm just to get the variable TFsum to do some calculations.

thanks
grady


Could you post the relevent code?

Ryan


All I'm trying now is get the TFsum value into the lblcompliant label.

thanks
grady

Imports System.Data
Imports System.Data.OleDB
Imports System.Data.OleDb.OleDbDataReader

Partial Class reports_508report
Inherits System.Web.UI.Page

Protected Sub SubmitBtn_Click(ByVal sender As Object, ByVal e As System.EventArgs)

If (Page.IsValid) Then

Dim ddlOA As String = ddloalist.SelectedValue

Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
"c:\accmon\database\accmon.mdb" & ";"
Dim MySQL As String = "SELECT SUM(filesfailed)AS TFsum FROM accmonreport WHERE oa='ddlOA' HAVING filesfailed=0"
Dim MyConn As New OleDbConnection(strConn)
Dim cmd As New OleDbCommand(MySQL, MyConn)
MyConn.Open()
cmd.ExecuteReader()
MyConn.Close()

lblCompliant.Text = " "

OAReport.SetActiveView(Result)
End If

End Sub

End Class


You need to make a couple of changes.

If (Page.IsValid) Then

Dim ddlOA As String = ddloalist.SelectedValue

Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
"c:\accmon\database\accmon.mdb" & ";"
Dim MySQL As String = "SELECT SUM(filesfailed)AS TFsum FROM accmonreport WHERE oa='" & ddlOA & "' HAVING filesfailed=0"
Dim reader As OleDbDataReader
Dim MyConn As New OleDbConnection(strConn)
Dim cmd As New OleDbCommand(MySQL, MyConn)
MyConn.Open()
reader =cmd.ExecuteReader()

While reader.Read()
lblCompliant.Text = reader("TFsum")
End While

reader.Close()
MyConn.Close()

OAReport.SetActiveView(Result)
End If

HTH,
Ryan


Thanks, I really appreciate your time and knowledge. If you don't mind, I have one more question. In Coldfusion there is a function that gives me a recordcount after every query. How do you implement something like that in .Net?

thanks
grady

Thursday, March 22, 2012

Suppress Masterpage

hi,
I am looking into reusing code to limit number of pages.
When ever I display a user's name on the site, It is with a hyperlink so you
can view the user profile in a popup window.
Is there a way to suppress the masterpage when a page is shown in my popup
windows?
JonasSure, just don't specify a master page for the popup window.
In the page header, don't add a MasterPageFile attribute.
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com
"Jonas Pedersen" <qwert@.qwerty.com> wrote in message
news:O$vof7RJIHA.484@.TK2MSFTNGP06.phx.gbl...
> hi,
> I am looking into reusing code to limit number of pages.
> When ever I display a user's name on the site, It is with a hyperlink so
> you can view the user profile in a popup window.
> Is there a way to suppress the masterpage when a page is shown in my popup
> windows?
> Jonas
>

Suppress Masterpage

hi,

I am looking into reusing code to limit number of pages.
When ever I display a user's name on the site, It is with a hyperlink so you
can view the user profile in a popup window.
Is there a way to suppress the masterpage when a page is shown in my popup
windows?

JonasSure, just don't specify a master page for the popup window.

In the page header, don't add a MasterPageFile attribute.

--
Jonathan Wood
SoftCircuits Programming
http://www.softcircuits.com
"Jonas Pedersen" <qwert@.qwerty.comwrote in message
news:O$vof7RJIHA.484@.TK2MSFTNGP06.phx.gbl...

Quote:

Originally Posted by

hi,
>
I am looking into reusing code to limit number of pages.
When ever I display a user's name on the site, It is with a hyperlink so
you can view the user profile in a popup window.
Is there a way to suppress the masterpage when a page is shown in my popup
windows?
>
Jonas
>

Tuesday, March 13, 2012

Switch from ASPNET/NETWORK SERVICE Account

Hi,

I have a page which requests info from a number of machines and whenever I try to do this I get an 'access is denied' error message. How do I change the account that my page is using to one which actually has access to the machines.

Thanksthere is not really a straight-forward answer to this.

if all of these servers are on the same domain, then you will ba able to impersoninate a common user in the web.config ..

<identity impersonate="true" userName="domain_name\user" password="password"/
make sure this user has the appropiate permissions on all the folders your are trying to access.

by default, the ASP.NET Machine Account is used for all requests.

psi
thanks psi
see if the framework and/or the ASP.NET Machine Account is on all machines ... if it is, and all the servers are on the same domain, you should be able to set the service to network service ...

psi
Is there any other way I could do this? There is a single account on the domain that I can use but its password is changed frequently and it is a account which my boss would prefer not to have hard-coded into the web.config file.

Thanks again,
Tomas