Solved

DateTime.Now  3 hours early

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
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.

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now