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
Solved

DateTime.Now  3 hours early

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

838 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