|
-
Feb 19th, 2005, 08:45 PM
#1
Thread Starter
Fanatic Member
DateDiff and SQL sort
Firstly i want to use DateDiff to establish the amount of time between a Login and Logout time? Can this be done? and what values can DateDiff return?
Also, how can i sort by Date using if i'm using an SQL statement? When i try to do this only the first segment of the date is sorted, but everything after the first slash isn't sorted. How can i sort using the whole date?
thanks
Last edited by x-ice; Feb 26th, 2005 at 08:01 PM.
-
Feb 19th, 2005, 08:56 PM
#2
Re: DateDiff and SQL sort
DateDiff(interval,Date1,Date2[,FirstDayofWeek[,FirstWeekOfYear]
Interval can be:
yyyy Year
q Quarter
m Month
y Day of Year
d Day
w Weekday
ww Week
h Hour
m Minute
s Second
FirstDayofWeek 0 - System Date
1 - Sunday
7 - Saturday
FirstWeekofYear 0 - System
1 Week when Jan 1 occurs
2 Has at least 4 days in it
3 First Full Week of year
Put the Interval in Quotes.
VB Code:
DateDiff("d",now,"2/20/05") = 1
Second question:
VB Code:
"SELECT * FROM tablename ORDER BY field2 DESC"
-
Feb 19th, 2005, 10:42 PM
#3
Re: DateDiff and SQL sort
The sorting issue may be from the field being a data type other then a Date/Time format.
So when you have, say a text field storing string date values, it will sort based on text
values and not date values.
If you need to retain a text field data type then you can format the field in whatever control
you presenting it in with a preceeding zero for single digit months and also for the days and
years, depending on how you want the format to be.
1/1/01 <-> 01/01/2005 This will sort correctly in either data or text formats.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Feb 20th, 2005, 03:48 PM
#4
Thread Starter
Fanatic Member
Re: DateDiff and SQL sort
Can DateDiff only return whole numbers?
i did
Code:
MsgBox DateDiff("h", "13:00:00", "16:30:00")
and it returned 3 instead of 3:30
p.s. the data type of Date is Date/Time and i know how to construct the SQL statement, but it doesn't work as explained earlier
-
Feb 20th, 2005, 03:56 PM
#5
Re: DateDiff and SQL sort
You could use Minutes instead
-
Feb 20th, 2005, 04:27 PM
#6
Thread Starter
Fanatic Member
Re: DateDiff and SQL sort
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|