DateTime Function

This is a discussion on "DateTime Function" within the Classic ASP section. This forum, and the thread "DateTime Function are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > Classic ASP

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old May 26th, 2006, 08:29
New Member
Join Date: May 2006
Location: united kingdom
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Thumbs down DateTime Function

In my database I have field named dateTime and in the web page i want to display the date in one column and the time in another. E.g.

dateTime = 01/01/2001 01.30.00

In the table i want to see

date - 01/01/2001
time - 01.30.00

How do i do this i have spent hours searching the internet and this is my last resort. The people this site is for want to keep the database field as it is shown above. So the easy answer is gone!

Any comments will be appreciated

Tanya
Reply With Quote

  #2 (permalink)  
Old May 26th, 2006, 16:28
New Member
Join Date: May 2006
Location: Norway
Age: 38
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Lightbulb Re: DateTime Function

If I have understood your questions right, I think you could just simply use the following DateTime-functions:

Year, Month, Day, Hour, Minute and Second.

With these functions you can extract the relevant part of your DateTime data and easily reconstructed it in the way you want. For example:

Date = Day(DateTime) & Month(DateTime) & Year(DateTime)
Time = Hour(DateTime) & Minute(DateTime) & Second(DateTime)

You may also want to check if the values resulting from the functions Day, Month, Hour, Minute and Second are less than 10 so that to prefix a Zero. In this way you ensure that dates and times are presented in the correct format (dd/mm/yyy and hh:mm:ss). For example 01/01/2006 and not 1/1/2006.

I hope this helps you.

Sincerely
Jacque
Reply With Quote
  #3 (permalink)  
Old Jul 11th, 2006, 02:14
New Member
Join Date: Jul 2006
Location: malaysia
Age: 27
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Re: DateTime Function

Quote:
Originally Posted by Jacque
If I have understood your questions right, I think you could just simply use the following DateTime-functions:

Year, Month, Day, Hour, Minute and Second.

With these functions you can extract the relevant part of your DateTime data and easily reconstructed it in the way you want. For example:

Date = Day(DateTime) & Month(DateTime) & Year(DateTime)
Time = Hour(DateTime) & Minute(DateTime) & Second(DateTime)

You may also want to check if the values resulting from the functions Day, Month, Hour, Minute and Second are less than 10 so that to prefix a Zero. In this way you ensure that dates and times are presented in the correct format (dd/mm/yyy and hh:mm:ss). For example 01/01/2006 and not 1/1/2006.

I hope this helps you.

Sincerely
Jacque
Hi Jacque,

I'm facing a problem to change my date format from eg : 1/July/2006 to 01/July/2006.

Tried to change setting the control panel but the result still the same.

Hope you can help.
Reply With Quote
  #4 (permalink)  
Old Mar 15th, 2007, 03:46
New Member
Join Date: Mar 2007
Location: delhi
Age: 27
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Re: DateTime Function

hello to all
Reply With Quote
  #5 (permalink)  
Old Mar 15th, 2007, 04:03
New Member
Join Date: Mar 2007
Location: delhi
Age: 27
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Unhappy Re: DateTime Function

Quote:
Originally Posted by poonam View Post
hello to all
Reply With Quote
  #6 (permalink)  
Old Oct 12th, 2007, 16:42
Most Reputable Member
Join Date: Feb 2004
Location: Borneo
Age: 27
Posts: 1,608
Blog Entries: 2
Thanks: 0
Thanked 4 Times in 3 Posts
Send a message via Yahoo to Monie
Re: DateTime Function

Quote:
Originally Posted by tanya_1985_am View Post
In my database I have field named dateTime and in the web page i want to display the date in one column and the time in another. E.g.

dateTime = 01/01/2001 01.30.00

In the table i want to see

date - 01/01/2001
time - 01.30.00

How do i do this i have spent hours searching the internet and this is my last resort. The people this site is for want to keep the database field as it is shown above. So the easy answer is gone!

Any comments will be appreciated

Tanya
Hai tanya,
You can perform 2 function to get it. One for date, and one for time. you also have to create 2 field in your database to store the date and time.
I have with me an example of date function in asp that might help you,
This will display dd/mm/yyyy (eg: 01/12/2007)
HTML: Select all
<%
        dim dd,mm,yyyy,date
        dd=day(date)
        if len(dd)=1 then
          dd="0" & dd
        end if
        mm=month(date)
        if len(mm)=1 then
          mm="0" & mm
        end if
        yyyy=year(date)
        
        'getting new date
        date = dd & "-" & mm & "-" & yyyy
        Session("date") = date
        response.write Session("date") 'to display the date in your page
        response.end
%>
you could write:

Code: Select all
<%
Dim date, time
date = Session("date")
time = time()
%>
after that you can perform the INSERt INTO function to insert the value to the database according to their field.
Last Blog Entry: ASP Programming Tips and Technique (Oct 26th, 2007)

Last edited by Monie; Oct 26th, 2007 at 04:12. Reason: change [CODE] to [HTML] to show some coloring code..
Reply With Quote
Reply

Tags
datetime, function

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
convert string to datetime format ... jeffmarsh Other Programming Languages 0 Jul 2nd, 2006 06:36
Getting value from function melvinoyh JavaScript Forum 2 May 27th, 2006 00:57
Macros/function letuan Databases 0 Aug 15th, 2005 12:04
SQL Function spinal007 Databases 1 Mar 25th, 2005 09:43
Needing function help stealthy1 JavaScript Forum 19 Jul 6th, 2004 15:13


All times are GMT. The time now is 06:37.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43