Solved

DateTime.Now  3 hours early

Posted on 2010-09-09
3
370 Views
Last Modified: 2012-05-10
Hello Folks I need to do a basic function in vb.net  and I dont know how to implement in datetime.

I've this variable:  Dim GetValue as string = DateTime.Now
and in my DB  I've this value: 09/08/2010 12:32:49

What I need to do:

For example Today is 09/09/2010 03:35:02
I need to create a function to get the this value: 09/08/2010 02:00:00

Why I need that:
Because I need to delete all entries in my dabaset with a entry date by yesterday + 2 hours.

Thanks
0
Comment
Question by:nkoriginal
3 Comments
 
LVL 25

Expert Comment

by:Luis Pérez
ID: 33635286
0
 
LVL 1

Assisted Solution

by:paultantony
paultantony earned 150 total points
ID: 33635434
Sample Code
Calling Function:
MsgBox(YesterdayPlus2hours(Now))


    Function YesterdayPlus2hours(ByRef dtValue As Date) As Date
        Dim yesterday As Date
        Dim yesterdayplus2hrs As Date
        ' go to yesterday
        yesterday = DateAdd(DateInterval.Day, -1, dtValue.Date)
        'add 2 hrs
        yesterdayplus2hrs = DateAdd(DateInterval.Hour, 2, yesterday)
        'Return the value
        Return yesterdayplus2hrs
        'Without using variables, one line code, you can comment above code to check
        'Return DateAdd(DateInterval.Hour, 2, DateAdd(DateInterval.Day, -1, dtValue.Date))
    End Function
0
 
LVL 8

Accepted Solution

by:
Mohit Vijay earned 350 total points
ID: 33635522
on VB.NET end, you need to write

Dim GetValue as string = DateTime.Now().AddDays(-1).Date().AddHours(2)
0

Featured Post

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question