Showing posts with label specific. Show all posts
Showing posts with label specific. Show all posts

Monday, March 12, 2012

get timezone specific date

Hello,

I am struggling with one algo i.e. I want to retrieve the date according to time zone

I have table called TIMEZONe in which i have the information about the hours difference (+12 to -12) from GMT...

now my scenario is that I want to get the date, using information from timezone area table (time difference from GMT), of any particluar time zone

can any one tell me, how will I able to achieve this task.

for example:

it 4:00 AM in the mornign in GMT TIME and date is 11-08-2006 but in US it 11:00 PM and date is 10-08-2006

Note: Server date is set to GMT (System date)

regards,

Anas

i HAVE DEVISED THE FOLLWING ALGO

IF @.OFFSET - DATEPART(HH,GETDATE())>=0

SET @.SYSDATE = GETDATE()

ELSE

SET @.SYSDATE = GETDATE()-1

PRINT @.CDATE

WHERE @.OFFSET IS NO. OF HOURS DIFFERENCE FROM GMT

ANY BETTER SOLUTIONS ARE WELCOME

REGARDS,

ANAS

|||

Where is the problem? If you have a TimeZone table you could use a query like this

select dateadd(hour, TimeZone.GMTDiff, getdate())

From TimeZone

Where Zone = 'US'

|||

THANX FOR YOUR BETTER SOLUTION

I DIDNT TRY THIS

I WAS USING DATEDIFF BUT COULDNT SOLVE THE PROB.

THANKS AGAIN

Get the specific files from directory

Hi,

I have some some files names in SQL DATABASE but my actuall files are keep in a seperate folder. so please help me that becasue i dont know that how i can select the specific files from folder and fetch into the imageArray according to the database table. In my coding its get the all files from directory but i want to get from database with where class and then select from directory.

The structure of my table is

create table event_pic
(
event_sub_id integer,
event_pic_name varchar(50)
)

here is code below:

Sub displayMe()

dim con as new SQLConnection("server=london-home; Database=tony; uid=rashid2; pwd=test; ")
dim cmd as new SQLCommand("select * from event_pic where event_sub_id='5' ",con)

con.open()

dim SDR as SQLDataReader
SDR = cmd.ExecuteReader()



con.close()


Dim imageArray() As String
Dim i As Integer

' grab full path and file of images on server in images folder
imageArray = Directory.GetFiles(Server.MapPath("upload/"), "*.*")

' remove the full path from the image filenames
For i = 0 To (imageArray.Length - 1)
imageArray(i) = Replace(imageArray(i), Server.MapPath("upload/"), "")

Next


ViewImages.DataSource = imageArray
ViewImages.DataBind()


End Sub

If you are using 2.0 you can solve it with a List.

Sub displayMe()Dim conAs New SqlConnection("server=london-home; Database=tony; uid=rashid2; pwd=test; ")Dim cmdAs New SqlCommand("select * from event_pic where event_sub_id='5' ", con) con.Open() Dim SDR As SqlDataReader SDR = cmd.ExecuteReader() Dim imageList As New List(Of String)() While SDR.Read() imageList.Add(SDR("event_pic_name").ToString())End While ViewImages.DataSource = imageList ViewImages.DataBind() con.Close()End Sub
|||

but the thing is that the database table only keeps the name of images actuall images are in a seperate folder and I will trace from folder according to the sql query.

|||

? In your initial query you strip out the path of the image, so imageArray will only contain the actual name of the image - without path. How do you want it? Does the entries in the database contain full path? Do you want to strip the path prior to binding?

|||

In my first query I get the files from DIRECTORY.GETFILES and then from loop I remove the paths and then bind to datagrid. anyway just pls tell me that the script that how I can get the specific files from folder according to the sql query?

|||

my database entries only keep only the names of files not full path

|||

If all your files are placed in the same folder, you can simply prefix the path of the image with that folder name. You should not use Server.MapPath for this, as it translates to a physical path. You need a virtual path in order serve the image URL correctly to the client. Also you must make sure that the image folder is located under the web root, either physically or through a virtual directory.

To get the correct virtual path in an asp.net app, you should use Page.ResolveUrl method.

So, the updated code would be:

imageList.Add(Page.ResolveUrl("~/imagefolder/") + SDR("event_pic_name").ToString())
|||

when i declare the image list its give me this error

Dim imageList As New List(Of String)()

Error: Type 'List' is not defined.|||

imports System.Collections.Generic

(Requires .net 2.0 or higher)

|||

Ok, Thanks but its display no images when i set the

ViewImage.DataList = imageList

ViewImage.Databound()

<asp:DataGrid runat="server" ID="ViewImages" AutoGenerateColumns="false" >
<columns>
<asp:TemplateColumn>
<itemtemplate>
<table id="tt" border="1" cellpadding="5" cellspacing="0">
<tr>
<td width="210"><img src="http://pics.10026.com/?src=upload/<%# Container.dataItem() %>" border="0" /></td>
</tr>
</table>
</itemtemplate>
</asp:TemplateColumn>
</columns>
</asp:DataGrid>

|||

You already have the image path specified in your asp.net code. You have to choose - either you have it there, or you have it in your page class. Can't have both, or else the path will be invalid. My suggestion is that you set the entire path from your page class, with the code I provided (Page.ResolveUrl). If you do a view source on the page, you should see that the images are there but the path is invalid.


|||

can you explain me that how i can set this path and shows the images through datagrid, My acutall path is in the root directory and name of the folder is "upload". and i use this script to get files

do while SDR.Read()

imageList.Add(Page.ResolveUrl("~/upload/") + SDR("event_pic").ToString())

Loop

|||

If you want to display only the pictures, I would recommend you to use a Repeater instead, as it is more logical.

See this tutorial:http://msconline.maconstate.edu/tutorials/ASPNET20/ASPNET08/aspnet08-01.aspx

Also, see this previous post:Using a repeater to display images side by side?

|||

hmmmm, My problem is still remain actually i am a newly person in asp.net and so thats why i have a some problem, suppose if i use repeater but how i can display the images because my database hold only the names of images and the images are in a seperate folder. Is it possible to write a short script for me I shall be very thankful to you.

|||

This is another way to do it, may not be the best, but it works.

<asp:GridViewrunat="server"ID="GridView1"AutoGenerateColumns="false">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<tableid="tt"border="1"cellpadding="5"cellspacing="0">
<tr>
<tdwidth="210">
<%# GetImage(Eval("imagename").ToString()) %>
</td>
</tr>
</table>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

Then inside the codebehind

Sub DataBindPhotos()

Dim mConAsNew SqlConnection("server=london-home; Database=tony; uid=rashid2; pwd=test;")

Dim mComAsNew SqlCommand("select * from event_pic where event_sub_id='5' ", mCon)

Dim myAdapAsNew SqlDataAdapterDim myTableAsNew DataTable

myAdap.SelectCommand = mCom

myAdap.Fill(myTable)

GridView1.DataSource = myTable

GridView1.DataBind()

End Sub

Function GetImage(ByVal ImageNameAsString)AsString

Return"<img src=path/to/your/pictures/" + ImageName +" border=0 />"

EndFunction

Friday, March 9, 2012

get the day from date value in SQL Server

Hello,

I want to know how can I (in sql server) get the day of week(eg Mon, Tue, Wed, etc) when a specific date is being given to the stored procedure. The day number will also do fine!!

In other words...I want to send a date to a stored procedure. Before anything in the sp can happen, I need to know the DayOfWeek the specified date falls on (day number also fine). Once I know the DayOfWeek I can continue with the rest of the work that actually needs to happen in the sp.

I know I can get the DayOfWeek in vb itself, but it would be easier if I can determine this in SQL Server and then just pass the date through as a paramater. If I have to get the DayOf Week in vb then I have to add a second paramater (one for DOW and one for the Date).

I hope the question is clear!?!

Give a look to books online to find the information you need. For a number to designate the day of the week, give a look to the DATEPART functon. For the name of the day of the week give a look to DATENAME. Hang on and I'll get you a couple of examples.

Here is a quick example. Note that DW is the designation for "Day of the Week:"

select datepart (dw, '5/11/7') as dayOfTheWeek,
datename (dw, '5/11/7') as NameOfDay

/*
dayOfTheWeek NameOfDay
6 Friday
*/

|||

Code Snippet

SELECT DATENAME (DW,GETDATE())

Gurpreet S. Gill

|||

Thanks guys!! I have been looking in the help files for SQl Server (2005), but I didn't spot it!!

Now that I have seen the solution, I remember that I have actually used it some time ago!!