Solved

DateTime.Now  3 hours early

Posted on 2010-09-09
3
368 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

803 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