Solved

DateTime.Now  3 hours early

Posted on 2010-09-09
3
373 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

617 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