|
Hi,
DateTime.Date sets you back to midnight, which is fine for a timeless date compare.
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
|
|
|
|
|
ya I have tried it. Its perfect
DateTime d1 = DateTime.Today;
DateTime d2 = DateTime.Today.AddMilliseconds(1);
if (d1.Date.CompareTo(d2.Date) == 0)
{
Response.Write("Ya its equal");
}
else
{
Response.Write("No its not equal");
}
Education is not a way to escape poverty — it is a way of fighting it.
|
|
|
|
|
Thanks Luc, is there any way to do date and time, without the MS? It's just possible that there might be multiple values for the same day, so that's not really fine grain enough for me!
-------------------------------
Carrier Bags - 21st Century Tumbleweed.
|
|
|
|
|
Hi,
it all depends on what you want exactly.
1.
if parts of the DateTime should be identical, then check those parts, as in:
DateTime dt1=...;
DateTime dt2=...;
if (dt1.Date==dt2.Date && dt1.Hours==dt2.Hours) isSufficientlyEqual();
the problem now is that 16:59:59 would equal to 16:00:00 and not to 17:00:00 which is much closer!
2.
if time distance is important, calculate it
DateTime dt1=...;
DateTime dt2=...;
if (dt1.Date==dt2.Date) {
float seconds=dt1.Subtract(dt2).TotalSeconds;
if (seconds>-100 && seconds<100) isSufficientlyClose();
}
3.
Up to the second equal:
DateTime dt1=...;
DateTime dt2=...;
if (dt1.AddMilliseconds(-dt1.MilliSeconds)==dt2.AddMilliseconds(-dt2.MilliSeconds)) {
isPrettyClose();
}
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
|
|
|
|
|
|
That's a nice idea! Something to stick in the Common Lib. ^^
-------------------------------
Carrier Bags - 21st Century Tumbleweed.
|
|
|
|
|
Ah, i was wondering if there was a existing or simpler way. I could have done it by now ><
I think between that and some extention methods, i can solve the problem nicely.
Cheers!
-------------------------------
Carrier Bags - 21st Century Tumbleweed.
|
|
|
|
|
Depending on which database you are using, you may see some loss of precision when you store a datetime (aka timestamp in some databases). SQL Server, for example, does not store datetime values to the exact millisecond. It is only accurate to approximately the nearest 3 milliseconds. So if it is important to get accurate timestamps right down to the exact millisecond, you should avoid the SQL Server datetime datatype.
SQL Server 2008 introduces a new datatype, datetime2, which is accurate to approximately 100ns to get around this problem.
Possible solutions:
- if you are using SQL Server 2008 and have ownership of the database, use datetime2 rather than datetime
- if you are not using SQL Server 2008 or you cannot change the table design and if you do not need millisecond accuracy, decide what accuracy you do need: for example, round off your timestamps to the nearest second before storing them
- if you do need millisecond accuracy, either convert the timestamp to a string format (OK for XML, not good for date functions and the conversion to and from datetime type may be slow) or store the timestamp as the number of milliseconds from the epoch (gives you the accuracy you need at a reasonable performance but not good for date functions)
|
|
|
|
|
I'm not too fussed about the loss of precision, i can deal with the nearest second. But thanks for the input. Is there any easy way to round a date? I've always created new dates and copied the relevant values over before.
-------------------------------
Carrier Bags - 21st Century Tumbleweed.
|
|
|
|
|
One of the earlier replies from Luc shows you how to do this. Yes, you have to create a new DateTime (it is immutable so once you've created one you can't change it) but there is an easy way to do it using AddMilliseconds. Sounds like a good candidate for an extension method if you're at the right version of .NET. Otherwise, a good old fashioned DateUtils class would do.
|
|
|
|
|
|
PIEBALDconsult wrote: May I humbly recommend DateTruncate?
Waiting for V2.0, with a Compare method added to it.
Luc Pattyn [Forum Guidelines] [My Articles]
DISCLAIMER: this message may have been modified by others; it may no longer reflect what I intended, and may contain bad advice; use at your own risk and with extreme care.
|
|
|
|
|
You'll be waiting a long time if you don't make a request.
I suppose I could make a TimespanTruncate.
|
|
|
|
|
Can I Shutdown my local Computer Using VB.Net?
shinoopmathew@gmail.com
009744931401
|
|
|
|
|
Yes.
Unless you are really fond of spam and viruses, you should not post your email address on a public forum.
People can contact you, as I have done, by replying to your post.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Yes. A quick Google Search can get you more guidance on it. Also, as the other poster advised you, refrain from publishing your private info like email address and telephone numbers on forums/webpages.
Vasudevan Deepak Kumar
Personal Homepage Tech Gossips
The woods are lovely, dark and deep,
But I have promises to keep,
And miles to go before I sleep,
And miles to go before I sleep!
|
|
|
|
|
|
|
Hi all
i am doing export to excel operation using below code.
public void ExcelExport(System.Data.DataTable tblExportData, string TempFilePath,string userInfo,bool headerStatus)
{
try
{
Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();
excelApp.Workbooks.Open(TempFilePath, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
//Writing Header in Excel
if (headerStatus == true)
{
for (int i = 0; i < tblExportData.Columns.Count; i++)
{
excelApp.Cells[7, i + 1] = tblExportData.Columns[i].ColumnName;
}
}
//Writing Data in Excel
for (int i = 1; i <= tblExportData.Rows.Count; i++)
{
for (int j = 0; j < tblExportData.Columns.Count; j++)
{
string colName = tblExportData.Columns[j].ColumnName;
excelApp.Cells[i + 7, j+1] = tblExportData.Rows[i-1][colName];
}
}
//Create a worksheet object
Microsoft.Office.Interop.Excel.Sheets sheets = excelApp.Worksheets;
//from the collection of worksheet select one worksheet
Microsoft.Office.Interop.Excel.Worksheet mySheet = (Microsoft.Office.Interop.Excel.Worksheet)sheets.get_Item(1);
//select the cell in the worksheet
Microsoft.Office.Interop.Excel.Range myCell1 = (Microsoft.Office.Interop.Excel.Range)mySheet.get_Range("A6", "A6");
myCell1.Value2 = userInfo;
myCell1.Font.Color = System.Drawing.Color.Black.ToArgb();
excelApp.Visible = true;
}
catch (Exception ex)
{
}
}
it's working fine in local. but when i deployed this on server(e.g.relience server) then it stops to work. i mean exporting to excel not working. Even it's not generating any error and page is redirecting also. can any one help me please.
thanks to you all in advance.
|
|
|
|
|
This is a cross post. Please ignore.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Hi all,
i want to open an existing word document in a folder in the project,path of that file is stored in oracle table.
When i click a link button a query should be executed to take the corresponding path,then with that path the file should be opened.
i tried like this..
Private Sub Linkbutton6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Linkbutton6.Click
Dim str As String
Dim command As String = "SELECT FILENAME FROM S_TR_BUILDDATA A WHERE 1= (SELECT COUNT(DISTINCT B.DATEOFBUILD ) FROM
S_TR_BUILDDATA B WHERE A.DATEOFBUILD <=B.DATEOFBUILD) "
Dim DFmenu As DataSet = Me.ExecuteSql(command)
str = DFmenu.Tables(0).Rows(0).Item(0)
System.Diagnostics.Process.Start(str)
' Response.Redirect(str)
End Sub
its getting filled in dataset..
but the file is not opening..
what shall i do???
thanks n regards,
kums
|
|
|
|
|
How to check the check boxes in the mailbox
by using the shift key.
|
|
|
|
|
anandbprem wrote: How to check the check boxes in the mailbox
by using the shift key.
Is that a question and then answer? Or is it something else. You might want to try and express that in a different way.
|
|
|
|
|
In datagridview when press any key then from that column select the Cell strats with that latter. How can i do tht the Grid is already bound.
|
|
|
|
|
Something like the following should get you started toward a solution.
private void yourDataGridView_KeyPress(object sender, KeyPressEventArgs e)
{
foreach (DataGridViewColumn column in yourDataGridView.Columns)
{
if (column.HeaderText.StartsWith(e.KeyChar.ToString()))
{
column.Selected = true;
break;
}
}
}
You will also need to pay attention to the EditMode property of the DataGridView , to stop the grid going into an edit state when the key is pressed. Read the documentation for EditMode for the options.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|